Page 1 of 1
Convert Unix Time to Date
Posted: Thu Dec 01, 2016 8:48 am
by ampandya
Hi
I have soap request coming back with the element called Expirydate which send me the Date(151467840000+00 ...... )?
i want to read this as date, can you help please?
Thanks
Re: Convert Unix Time to Date
Posted: Thu Dec 01, 2016 11:15 am
by c-tec
Hello,
this is the way to create such a UNIX date, you can convert it back the same way. IsLeap() is a TOOLS III Function
regards
Rudolf
Code: Select all
*******************
Function DateAsSecs( _dDate )
*******************
Local nDays := 0
Local nSecs := 0
Local dStartDate := CToD( '01.01.1970' )
Local nStartDate := 1970
Local nYear := Year( _dDate )
Local nDoY := DoY( _dDate )
Local nDaysSecs := ( nDoY * 86400 )
Local i
For i := nStartDate To nYear
If IsLeap( CToD( '01.01.' + Str( i, 4 ) ) )
nDays += 366
Else
nDays += 365
EndIf
Next
nSecs := ( nDays * 86400 )
nSecs += nDaysSecs
Return ( nSecs )
Re: Convert Unix Time to Date
Posted: Fri Dec 02, 2016 5:10 am
by skiman
Hi,
If you just need the date:
ctod("01/01/70") + int(1514678400/86400) will give the date.
In this case the result is: 31/12/2017.
To calculate your unix date string.
(date()- ctod("01/01/70")) * 86400
Re: Convert Unix Time to Date
Posted: Sat Dec 03, 2016 8:24 am
by ampandya
Thank you very much for your replies, Rudolf and Chris
Chris's code works perfect.
Thanks
Pandya