Question
Viroj (Pat) Pad... · Feb 28, 2020

How to convert UTC to Eastern time

Does anyone know how to convert UTC to Eastern time in the DTL?  Input format "YYYYMMDDHHMMSS".

Can I use ConvertDateTime() function? If yes, what value do I use in these fields informat, outformat and outf?

Thank you.

0
0 443
Discussion (6)3
Log in or sign up to continue

I put in "%K(+5)" in the informat, and it gave me current eastern time, and not the date and tine that I tried to convert.  When I put "%K(+5)" in the outformat, it didn't do anything. The date/time didn't get converted.

Thanks.

The following works for me:

TESTING>write ##class(Ens.Util.FunctionSet).ConvertDateTime("20200228210000",  "%K(0)%q",  "%K(-5)%q")
20200228160000

 I didn't have the correct syntax. It is working now. Thank you very much.

HI Marc - how about during daylight savings time? Does this routine take care of that case even though we are specifying %K(-5)? May be use  $System.Util.IsDST() and do -4 if true.

Edit: That check if DST will not work if the input timestamp falls in DST but we are doing the conversion outside of that. There has to be an easier way to convert this (may be against the local OS timezone or something).

%K(-5) wouldn't take care of DST automatically. $ZDATETIMEH(myUTCTime, -3) will convert a $HOROLOG format (actually $ZTIMESTAMP format) value of UTC time into a $HOROLOG value in local time. So you can first use ConvertDateTime with %q(4) to convert to $ZTIMESTAMP format, then use $ZDATETIMEH with -3 to convert to local time, then use ConvertDateTime (or $ZDATETIME) to convert the $HOROLOG format back into a formatted date/time string.

https://docs.intersystems.com/healthconnectlatest/csp/docbook/Doc.View.c...

https://docs.intersystems.com/healthconnectlatest/csp/docbook/Doc.View.c...