Page 1 of 1

TimeStamp Math

Posted: Wed Aug 09, 2017 4:31 am
by DaveH
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.

Re: TimeStamp Math

Posted: Wed Aug 09, 2017 12:43 pm
by Stewart Marshall
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

Re: TimeStamp Math

Posted: Fri Aug 11, 2017 3:58 am
by DaveH
Thanks, this will work great.

Re: TimeStamp Math

Posted: Thu Aug 17, 2017 4:32 am
by atostaine
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 )

Re: TimeStamp Math

Posted: Wed Nov 14, 2018 1:41 am
by Mkolbe
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.

Re: TimeStamp Math

Posted: Wed Nov 14, 2018 9:53 am
by dannyoorburg
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