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.
dvanoni
Posts: 37 Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland
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.
JamesDuignan
Posts: 85 Joined: Thu Nov 26, 2015 1:43 pm
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: 37 Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland
Post
by dvanoni » Wed May 29, 2019 7:45 pm
Thanks a lot! It works
MARCOREMMEDATA
Posts: 14 Joined: Mon Apr 11, 2022 4:48 pm
Location: ITALIA
Contact:
Post
by MARCOREMMEDATA » Tue Apr 12, 2022 12:31 am
If it is useful, here is the routine for calculating the difference in seconds between two date-time
Code: Select all
* ---------------------------------------------------------------------------------
* DIFFERENZA IN SECONDI TRA DUE DATE
* ---------------------------------------------------------------------------------
MTHROUTINE NAME(um_DateDifference)
DEFINE_MAP FOR(*INPUT) CLASS(£RTE_DTGEN) NAME(£p_DaData) HELP("YYYYMMDD")
DEFINE_MAP FOR(*INPUT) CLASS(£R_NU0600) NAME(£p_DaOra) HELP("HHMMSS")
DEFINE_MAP FOR(*INPUT) CLASS(£RTE_DTGEN) NAME(£p_AData) HELP("YYYYMMDD")
DEFINE_MAP FOR(*INPUT) CLASS(£R_NU0600) NAME(£p_AOra) HELP("HHMMSS")
DEFINE_MAP FOR(*RESULT) CLASS(£RTE_N1500) NAME(£p_Result) HELP("SECONDI")
* 01/01/2022-00:00:00 01:15:10 11/04/2022-00:00:00 16:20:58
* |_______________________|_______________________|________________________|
* DaData DaOra AData AOra
*
* |----------(b)----------|----------(c)----------|----------(a)-----------|
* |----------------------(y)----------------------|
* |-----------------------(x)----------------------|
*
* y=b+c -> c=y-b
* x=c+a-> x=(y-b)+a
* Calcolo la differenza in secondi tra le due date (y)
£p_Result := £p_AData.AsDate( CCYYMMDD ).Difference( £p_DaData.AsDate( CCYYMMDD ) ) * 86400
* Calcolo i secondi trascscorsi dalla mezzanotte del giorno più lontano (b)
£p_Result := £p_Result - £p_DaOra.AsTime( HHMMSS ).Difference( (000000).AsTime( HHMMSS ) )
* Calcolo i secondi trascscorsi dalla mezzanotte del giorno più recente (a)
£p_Result := £p_Result + £p_AOra.AsTime( HHMMSS ).Difference( (000000).AsTime( HHMMSS ) )
ENDROUTINE
MARCO ROSSI | Software Developer Sr. - Software Production