Question
· Sep 3

Wrong data conversion when returning ZTIMEH and ZTIME

I encountered an unexpected behavior while working with the $ZTIMEH and $ZTIME functions, specifically with times between 12:00 and 13:00. Here's what I observed:

 

W $ZTIMEH("08:50:38.975411826")
Output: 31838 

W $ZTIME(31838,1)
Output: 08:50:38
 

This behavior is correct as $ZTIME returns the expected time of 08:50:38.

However, with the following example:
 

W $ZTIMEH("12:05:38.975411826")
Output: 338

W $ZTIME(338,1)
Output: 00:05:38

 

This seems incorrect to me. $ZTIME should have returned 12:05:38, but instead it returns 00:05:38.

Based on our findings, this appears to only occur at times between 12pm and 1pm (12h/13h).

Has anyone else had this problem or found a workaround?

Product version: IRIS 2022.1
Discussion (2)1
Log in or sign up to continue

This is the part that's not behaving as expected:

W $ZTIMEH("12:05:38.975411826")
Output: 338

On my instance I get Output: 43538.975411826

$ZTH takes a 2nd argument that specifies the time format.  If you omit that value it uses the default, which you can see with this:

WRITE ##class(%SYS.NLS.Format).GetFormatItem("TimeFormat")

I suspect you'll get 3 or 4, since those are the formats for 12 hour clock.

Try sending 1 or 2 for 24 hour clock:

W $ZTIMEH("12:05:38.975411826", 1)

https://docs.intersystems.com/iris20241/csp/docbook/Doc.View.cls?KEY=RCO...