Epoch & Unix Timestamp

Moderator: Rathinagiri

Post Reply
User avatar
RussBaker
Posts: 51
Joined: Wed Jul 22, 2015 9:44 am

Epoch & Unix Timestamp

Post by RussBaker »

I need to calculate the Unix Time stamp.

eg: The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds

Is there a function that does this built in?
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Epoch & Unix Timestamp

Post by CalScot »

I don't know whether there's one built in, but this may help:

function getposix()
posixday = date() - ctod("01/01/1970")
posixhrs = posixday * 24
posixmin = posixhrs * 60
posixsec = posixmin * 60
tdyhrs2sec = int(val(substr(time(),1,2))) * 3600
tdymin2sec = int(val(substr(time(),4.2))) * 60
tdysec2sec = int(val(substr(time(),7,2)))
todaysec = tdyhrs2sec + tdymin2sec + tdysec2sec
Return posixsec + todaysec

It may be off by one day (86,400 seconds), but if you have something to compare it to, that should be easily fixed.
And I'm not sure about the difference from wherever you are to GMT, but again, if that's an issue, it would be a constant or an easily built-in variable.
User avatar
RussBaker
Posts: 51
Joined: Wed Jul 22, 2015 9:44 am

Re: Epoch & Unix Timestamp

Post by RussBaker »

That might be a start.

Foxpro works with this. Still have to adjust for time zone.
DATETIME() - {^1970/01/01 00:00:00}

HMG doesn't work. It returns a totally wrong number.

I need this to be accurate to the minute.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Epoch & Unix Timestamp

Post by serge_girard »

Russ,

If you can't get it with HMG then do a trick. Execute a small PHP program (which does give the time) and retrieve the output. A bit tricky but it should work. That's how I retrieve my IPADDRESS.

If you want to use this, let me known for the details.
Serge
There's nothing you can do that can't be done...
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Epoch & Unix Timestamp

Post by esgici »

RussBaker wrote:I need to calculate the Unix Time stamp.

eg: The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds

Is there a function that does this built in?
Please look at here.

By the way; are you sure that literal date time value operator {^ } supporting by Harbour ?


Viva HMG :D
Viva INTERNATIONAL HMG :D
User avatar
RussBaker
Posts: 51
Joined: Wed Jul 22, 2015 9:44 am

Re: Epoch & Unix Timestamp

Post by RussBaker »

esgici wrote:By the way; are you sure that literal date time value operator {^ } supporting by Harbour ?
It compiled and ran. However, the result was incorrect. So you are probably correct in that Harbour doesn't support "^".
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Epoch & Unix Timestamp

Post by esgici »

RussBaker wrote:
esgici wrote:By the way; are you sure that literal date time value operator {^ } supporting by Harbour ?
It compiled and ran. However, the result was incorrect. So you are probably correct in that Harbour doesn't support "^".
Definitely Harbour supports this VFP like datetime constant notation. But probably date-time implementation is different. Here some information found, hopefully may be helpful for you.



Viva HMG :D
Viva INTERNATIONAL HMG :D
Post Reply