Written by

Technical Delivery Master at Deloitte
Question Michael Wood · 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

Comments

Matjaz Murko · Jan 30

Hi.

Try:
$SYSTEM.SQL.Functions.DATEADD("HH",-3,$H)

0
Oliver Thompson  Feb 26 to Matjaz Murko

This is the correct answer. $SYSTEM.SQL.Functions.DATEADD() will allow you add/subtract based on any of the date parts.

0
Ian Pears · Jan 31

you could try 

w $ZDATETIME(+$H_","_($p($h,",",2)-10800),3)

there will be many ways.

0
Robert Cemper  Jan 31 to Ian Pears

this fails with <ILLEGAL VALUE> if time part is negative  (before 3AM) 

0
Ian Pears  Jan 31 to Robert Cemper

so it would - thanks Robert

0
Lynn Wu · Feb 25

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)

0
Robert Cemper  Feb 25 to Lynn Wu

slightly shorter using Julian Date

USER>set hours=-3write$zdt($zdth(hours*3600+$zdt($h,-2),-2))

Sorry, I just couldn't resist

0