Written by

Question Jow Black · May 17, 2023

How to convert UTC to BST considering the 1-hour daylight saving time offset during UK summer time.

I would like guidance on the most effective approach for converting UTC time, such as "2023-11-24T14:00:00.000Z," to the format "202311241400," while taking into account the 1-hour time difference during UK summer time. Any suggestions or advice would be greatly appreciated.

Product version: IRIS 2022.1
$ZV: IRIS for Windows (x86-64) 2022.1.2

Comments

Gio Ciampa · May 17, 2023

This seems to do the trick (I'm using Caché 2017.2, but I presume little has changed since?):
SET utc="2023-05-17T09:37:03.123456Z"
SET loc=$ZDATETIME($ZDATETIMEH($ZDATETIMEH(utc,3,7),-3),3,7,6)
ZWRITE utc,loc
utc="2023-05-17T09:37:03.123456Z"
loc="2023-05-17T10:37:03.123456Z"
The "SET loc=..." conversion works as follows:
The inner ZDATETIMEH converts ISO format to $H format
The outer ZDATETIMEH converts UTC time (in $H format) to local time (again in $H format)
The outermost $ZDATETIME converts $H format back to ISO format (the final 6 is the number of decimal places)
If you need to remove the ":-TZ" characters a $TRANSLATE will do that for you.

0