Epoch timestamp (ISO 8601) from datetime in Lansa (solved)

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
dvanoni
Posts: 27
Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland

Epoch timestamp (ISO 8601) from datetime in Lansa (solved)

Post by dvanoni » Tue May 28, 2019 4:36 pm

Hi!
Is it possible to get epoch timestamp (ISO 8601) from datetime in Lansa? I tried to use PRIM_DC.Duration class but this is what I get:

Code: Select all

Define_Com Class(#PRIM_DC.Duration) Name(#duration)
Define Field(#ts) Type(*DATETIME)
Define Field(#string) Type(*VARCHAR)
#duration := #ts.Now.AsDuration
#string := #duration.AsString
The result is 'P' (?).

How can I get the correct value?
Thanks
Last edited by dvanoni on Wed May 29, 2019 7:45 pm, edited 1 time in total.

dannyoorburg
Posts: 145
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Re: Epoch timestamp (ISO 8601) from datetime in Lansa

Post by dannyoorburg » Tue May 28, 2019 4:53 pm

Hi,

I think you're after:

Code: Select all

#STD_DTIMX.AsDisplayString( TZ )
as per

https://docs.lansa.com/14/en/lansa016/p ... string.htm

but I might very well be wrong....

Thought I post it anyway.

Regards,
Danny

dvanoni
Posts: 27
Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland

Re: Epoch timestamp (ISO 8601) from datetime in Lansa

Post by dvanoni » Tue May 28, 2019 6:43 pm

Thanks Danny for your reply.

Unfortunately it's not what I'm looking for. What I'm trying to do with Lansa is to get an epoch(Unix) timestamp from a datetime. For example:
from 2019-05-2808:33:05 to 1559032385000. You can refer to this website for more clarification https://www.epochconverter.com/.

Looking Lansa guide I found this https://docs.lansa.com/14/en/lansa016/p ... ration.htm for the class ISO standard duration (8601?) and this method https://docs.lansa.com/14/en/lansa016/p ... ration.htm to convert datetime into duration. But once I got the object duration from datetime I'm not able to get its correct value...

Any idea?

Thanks

JamesDuignan
Posts: 56
Joined: Thu Nov 26, 2015 1:43 pm

Re: Epoch timestamp (ISO 8601) from datetime in Lansa

Post by JamesDuignan » Wed May 29, 2019 4:52 pm

Hi,

To get this you would do a day difference between 1970-01-01 and today times this by 86400 for seconds then add on the seconds from midnight using the time as seconds intrinsic.

it would look something like:

Code: Select all

#STD_INT := (#DateTimex.Now.Date.Difference( 1970-01-01 ) * 86400) + #DateTimex.Time.AsSeconds
here is an example in web page:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>) Layoutmanager(#Layout1)

Define_Com Class(#PRIM_TBLO) Name(#Layout1)
Define_Com Class(#PRIM_TBLO.Row) Name(#Layout1Row1) Displayposition(1) Parent(#Layout1)
Define_Com Class(#PRIM_TBLO.Column) Name(#Layout1Column1) Displayposition(1) Parent(#Layout1)
Define_Com Class(#PRIM_TBLO.Item) Name(#Layout1Item1) Column(#Layout1Column1) Manage(#UnixDateTime) Parent(#Layout1) Row(#Layout1Row1) Sizing(ContentWidthAndHeight)

Define_Com Class(#prim_md.Label) Name(#UnixDateTime) Parent(#COM_OWNER) Displayposition(1) Tabposition(1) Left(595) Top(395) Themedrawstyle('Title') Height(10) Width(10)


Define_Com Class(#PRIM_TIMR) Name(#Timer) Interval(500)


Evtroutine Handling(#Timer.Tick)

#STD_INT := (#datetimex.Now.Date.Difference( 1970-01-01 ) * 86400) + #datetimex.Now.Time.AsSeconds

#UnixDateTime := #STD_INT.AsString

Endroutine
End_Com

dvanoni
Posts: 27
Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland

Re: Epoch timestamp (ISO 8601) from datetime in Lansa

Post by dvanoni » Wed May 29, 2019 7:45 pm

Thanks a lot! It works

Post Reply