$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
Comments
Hi.
Try:
$SYSTEM.SQL.Functions.DATEADD("HH",-3,$H)
This is the correct answer. $SYSTEM.SQL.Functions.DATEADD() will allow you add/subtract based on any of the date parts.
you could try
w $ZDATETIME(+$H_","_($p($h,",",2)-10800),3)
there will be many ways.
this fails with <ILLEGAL VALUE> if time part is negative (before 3AM)
so it would - thanks Robert
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)
slightly shorter using Julian Date
USER>set hours=-3write$zdt($zdth(hours*3600+$zdt($h,-2),-2))Sorry, I just couldn't resist