Page 1 of 1
Epoch & Unix Timestamp
Posted: Tue Dec 08, 2015 10:19 pm
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?
Re: Epoch & Unix Timestamp
Posted: Tue Dec 08, 2015 11:09 pm
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.
Re: Epoch & Unix Timestamp
Posted: Wed Dec 09, 2015 12:25 am
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.
Re: Epoch & Unix Timestamp
Posted: Wed Dec 09, 2015 8:08 am
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
Re: Epoch & Unix Timestamp
Posted: Wed Dec 09, 2015 1:07 pm
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

Re: Epoch & Unix Timestamp
Posted: Wed Dec 09, 2015 2:46 pm
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 "^".
Re: Epoch & Unix Timestamp
Posted: Wed Dec 16, 2015 10:42 pm
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
