Convert Unix Time to Date

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
ampandya
Posts: 58
Joined: Tue Apr 19, 2016 4:48 am

Convert Unix Time to Date

#1 Post 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

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: Convert Unix Time to Date

#2 Post 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 )
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Convert Unix Time to Date

#3 Post 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
Best regards,

Chris.
www.aboservice.be

ampandya
Posts: 58
Joined: Tue Apr 19, 2016 4:48 am

Re: Convert Unix Time to Date

#4 Post by ampandya »

Thank you very much for your replies, Rudolf and Chris

Chris's code works perfect.

Thanks
Pandya

Post Reply