Question
· Aug 7

DateTimeDifference in seconds

Hi All ,

I have a dateTime in the format = "2024-08-07 17:58:51.563"
I need the difference between current date time and above one 
I need it in seconds.

Discussion (5)2
Log in or sign up to continue

Hi Krishnaveni, 

$HOROLOG is an ObjectScript special variable that contains the local date and time for the current process. It can be used to grab the current date and time for the comparison. 

I used $zdatetime to convert the $HOROLOG (in my code shortened with $h) to convert the current time to the same format you provided as YYYY-MM-DD HH:MM:SS. Currently as I did this the value returned was 2024-08-07 13:46:13.

> w $zdatetime($h, 3)
2024-08-07 13:46:13

Then, a classmethod Diff() from class %Library.UTC can be used to perform the difference calculation and returns the difference in seconds. 

> w ##class(%Library.UTC).Diff($zdatetime($h,3), "2024-08-07 17:58:51.563")
-15063.563

Returns value in seconds that the time you provided is 4 hours and 11 minutes ahead the current time.