Question
· Feb 21, 2019

How do I convert timestamp to utc?

I have a date in this format: "YYYY-MM-DD HH:MM:SS+HHMM" how can I convert it to UTC?

write $zdth("2018-02-01 00:00:00+0600",3,5)
>64680,0
write $zdt("64680,0",3,5)
>2018-02-01T00:00:00+03:00

As you see, timezone is lost. Docs for $zdth in timeopt (5) state: Specify time in the form "hh:mm:ss+/-hh:mm" (24-hour clock). The time is specified as local time. The following optional suffix may be supplied, but is ignored: a plus (+) or minus (–) suffix followed by the offset of local time from Coordinated Universal Time (UTC)

Discussion (2)1
Log in or sign up to continue

If you massage the timestamp format a bit so it is ISO8601/XSD compatible, you can use the XSDToLogical method of %TimeStamp to do the conversion for you:

DEV>Set ts = "2018-02-01 00:00:00+0600"
DEV>Set ts = $Translate(ts, " ", "T")
DEV>Set ts = $Extract(ts, 1, *-2)_":"_$Extract(ts, *-1, *)
DEV>Write ts
2018-02-01T00:00:00+06:00
DEV>Write ##class(%TimeStamp).XSDToLogical(ts)
2018-01-31 18:00:00