Question Krishnaveni Kapu · Aug 7, 2024

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.

Comments

Julius Kavay · Aug 7, 2024
ClassMethod TimeDiff(inpTime = "2024-08-07 17:58:51.563")
{
	set current=$h// or $now(tz-offset)set inpTime=$zdth(inpTime,3)
	quit current-inpTime*86400+$p(current,",",2)-$p(inpTime,",",2)
}
0
Hannah Sullivan · Aug 7, 2024

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-0713: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.

0
Krishnaveni Kapu  Aug 7, 2024 to Eduard Lebedyuk

Thank you .This Worked for me.

DATEDIFF('s',inputDt,NOW())

0