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
.png)
.png)
.png)
Comments
Try sending the CreatedDate format like this, which is the format used by JSON serializers.
"2019-08-26T16:38:26.893Z"
Hi Rubens,
How to convert current date in "2019-08-30T16:38:26.893Z" this format.
My field has timestamp datatype.
I have tried below code.
$zdt($zu(188),3,1)
$ZDATETIME($NOW())
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.
Thanks Rubens,
It is working fine.