Page 1 of 1
Epoch timestamp (ISO 8601) from datetime in Lansa (solved)
Posted: Tue May 28, 2019 4:36 pm
by dvanoni
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
Re: Epoch timestamp (ISO 8601) from datetime in Lansa
Posted: Tue May 28, 2019 4:53 pm
by dannyoorburg
Hi,
I think you're after:
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
Re: Epoch timestamp (ISO 8601) from datetime in Lansa
Posted: Tue May 28, 2019 6:43 pm
by dvanoni
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
Re: Epoch timestamp (ISO 8601) from datetime in Lansa
Posted: Wed May 29, 2019 4:52 pm
by JamesDuignan
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
Re: Epoch timestamp (ISO 8601) from datetime in Lansa
Posted: Wed May 29, 2019 7:45 pm
by dvanoni
Thanks a lot! It works
Re: Epoch timestamp (ISO 8601) from datetime in Lansa (solved)
Posted: Tue Apr 12, 2022 12:31 am
by MARCOREMMEDATA
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