Question
· Jan 30

$ZDATETIME($HOROLOG,3) - 3 hours

Anyone know how to subtract three hours from  $ZDATETIME($HOROLOG,3)?

If $ZDATETIME($HOROLOG,3) returns 2025-01-30 10:17:04, I would like $ZDATETIME($HOROLOG,3) - 3 hours to return 2025-01-30 07:17:04

Product version: IRIS 2023.1
Discussion (7)3
Log in or sign up to continue

You would need to manually roll back to the previous day to handle before 3am if you are subtracting 3 hours in seconds:

set newH = $H
set timeInSeconds = $PIECE(newH, ",", 2)
set timeInSeconds = timeInSeconds - (3 * 3600)  ;  Subtract 3 hours in seconds

if (timeInSeconds < 0) {  
    set newH = $PIECE(newH, ",", 1) - 1_","_(86400 + timeInSeconds)  ; Roll back to previous day
} else {
    set $PIECE(newH, ",", 2) = timeInSeconds
}

write $ZDATETIME(newH,3)