TimeStamp Math

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
DaveH
Posts: 10
Joined: Tue May 17, 2016 1:35 am

TimeStamp Math

Post by DaveH » Wed Aug 09, 2017 4:31 am

I currently have a timestamp and need to add 51.5 hours to the time stamp to get a new date/time.

I cannot I anything in the documentation for this.

User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: TimeStamp Math

Post by Stewart Marshall » Wed Aug 09, 2017 12:43 pm

There are no intrinsic functions to modify times at present, so a little bit of manipulation is required

Simplest technique I think it to turn everything in to seconds and the back in to a date and time.

Here's a very rough and ready version. This only works for positive values.

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Height(448) Width(640) Theme(#SYS_THEME<2015Blue>)
Define_Com Class(#xDemoDateTime.Visual) Name(#StartDate) DisplayPosition(2) Height(25) Left(16) Parent(#COM_OWNER) TabPosition(2) Top(16) Caption('Start') LabelType(Caption) Width(581)
Define_Com Class(#xDemoDateTime.Visual) Name(#ResultDate) DisplayPosition(1) Height(25) Left(16) Parent(#COM_OWNER) TabPosition(1) Top(80) Caption('Result') LabelType(Caption) Width(581)
Define_Com Class(#xDemoNumber.SpinEdit) Name(#Increment) DisplayPosition(3) Left(16) Parent(#COM_OWNER) TabPosition(3) Top(48) Height(25) Caption('Increment in seconds') LabelType(Caption)

Evtroutine Handling(#COm_owner.CreateInstance)

#StartDate := #StartDate.Now

Endroutine

Mthroutine Name(IncrementDateTimeInSeconds)
Define_Map For(*Input) Class(#Prim_dat) Name(#DateTime)
Define_Map For(*Input) Class(#xDemoNumber) Name(#Seconds)
Define_Map For(*Result) Class(#Prim_dat) Name(#Result)

Define_Com Class(#Prim_date) Name(#Date)
Define_Com Class(#prim_nmbr) Name(#SecondsInaDay) Value(86400)
Define_Com Class(#Prim_nmbr) Name(#HH)
Define_Com Class(#Prim_nmbr) Name(#MM)
Define_Com Class(#Prim_nmbr) Name(#SS)

* Increment Seconds by the number of seconds of the current time
* All math can then be based on midnight
#Seconds += #DateTime.Time.AsSeconds

* Increment date by the number of days in the second
#Date := #DateTime.Date.Adjust( #Seconds.Div( #SecondsInaDay ) )

* Reduce the seconds by the number of days already used
#Seconds := #Seconds - ((#SecondsInaDay * #Seconds.Div( #SecondsInaDay )))

* Derive a time from the remaining seconds
#HH := #Seconds / 3600

#MM := (#Seconds - (#HH * 3600)) / 60

#SS := #Seconds - (#HH * 3600) - (#MM * 60)

#Result := (("&1-&2-&3 &4:&5:&6").Substitute( #Date.Year.AsString #Date.Month.AsString #Date.Day.AsString #HH.AsString #MM.AsString #SS.AsString )).AsDateTime( ISO )

Endroutine

Evtroutine Handling(#StartDate.Changed #Increment.Changed)

#ResultDate := #Com_owner.IncrementDateTimeInSeconds( #StartDate #Increment )

Endroutine

End_Com
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au

DaveH
Posts: 10
Joined: Tue May 17, 2016 1:35 am

Re: TimeStamp Math

Post by DaveH » Fri Aug 11, 2017 3:58 am

Thanks, this will work great.

atostaine
Posts: 395
Joined: Wed Jan 20, 2016 7:38 am

Re: TimeStamp Math

Post by atostaine » Thu Aug 17, 2017 4:32 am

Using substitute like this is an awesome idea.

Code: Select all

#Result := (("&1-&2-&3 &4:&5:&6").Substitute( #Date.Year.AsString #Date.Month.AsString #Date.Day.AsString #HH.AsString #MM.AsString #SS.AsString )).AsDateTime( ISO )
Art Tostaine

Mkolbe
Posts: 15
Joined: Tue Apr 04, 2017 12:45 am

Re: TimeStamp Math

Post by Mkolbe » Wed Nov 14, 2018 1:41 am

I'm wondering if I will need to do something similar for my issue.

I am attempting to display a data field from a SQL database that is stored as Datetime2. The time is stored in that database as our literal local time (not UTC). For example - 2018-11-12 14:56:00.0000000.

Within Lansa, I have defined the field as Date Time (26).

No matter how I setup the Input and Output Atrributes on the field in Lansa, the resulting display shows the date as 2 DAYS and 5 HOURS earlier than the actual datetime value from the SQL Database. In my example the date/time displayed is 11/10/2018 9:56:00 AM.

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

Re: TimeStamp Math

Post by dannyoorburg » Wed Nov 14, 2018 9:53 am

Hi,

just double checking, you have re-compiled all the objects that use that field (and therefor those attributes), including the file?

I've struggled with 9/10 hour unexplained difference in the past (I'm in Australia :)), but never multiple days.

And changing those attributes should do something..

Danny

Post Reply