Question Viroj (Pat) Padyandorn · 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.

Comments

Viroj (Pat) Padyandorn  Feb 28, 2020 to Marc Mundt

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.

0
Marc Mundt  Feb 28, 2020 to Viroj (Pat) Padyandorn

The following works for me:

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

0
Viroj (Pat) Padyandorn  Feb 28, 2020 to Marc Mundt

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

0
Ravi Akkiraju  Dec 1, 2020 to Marc Mundt

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).

0
Marc Mundt  Dec 2, 2020 to Ravi Akkiraju

%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…

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

0