Question
· Aug 26, 2019

ERROR #9406: Unexpected format for value of field

I got below error when passing Date in timestamp format.

I am using %JSON.Adaptor. Please refer screen 2

Discussion (4)0
Log in or sign up to continue
set ts = $zdt($zts, 3) // there's no timezone on it
set date = $piece(ts, " ", 1) 
set time = $piece(ts, " ", 2)

return $$$FormatText("%1T%2Z", date, time) // So we force it to use Z.

If you use $now(), you'll either need take out the timezone offset or change the Z to -hh:00 / +mm:00 which represents the timezone. So I'd recommend you to use $ztimestamp instead.

You can also use the %UTC class's NowUTC() if you are using a recent Caché version, let's say... 2017 onwards. But you still need to edit the value to include the T and Z, since this method also doesn't put it.

set ts = ##class(%UTC).NowUTC() // this includes milliseconds precision.
set date = $piece(ts, " ", 1) 
set time = $piece(ts, " ", 2)

return $$$FormatText("%1T%2Z", date, time) // So we force it to use Z.