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: 37
Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland

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

Post 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
Last edited by dvanoni on Wed May 29, 2019 7:45 pm, edited 1 time in total.
dannyoorburg
Posts: 177
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

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

Post by dannyoorburg »

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: 37
Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland

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

Post 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
JamesDuignan
Posts: 85
Joined: Thu Nov 26, 2015 1:43 pm

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

Post 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
dvanoni
Posts: 37
Joined: Wed Dec 02, 2015 3:47 am
Location: Chiasso - Switzerland

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

Post by dvanoni »

Thanks a lot! It works
User avatar
MARCOREMMEDATA
Posts: 14
Joined: Mon Apr 11, 2022 4:48 pm
Location: ITALIA
Contact:

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

Post 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
MARCO ROSSI | Software Developer Sr. - Software Production
Post Reply