Dateconversion
Hi Community,
I need to convert date 1997-08-09 10:38:39.700000000 into this format 1997-08-09T10:38:39Z
I have tried using all date function $ZDH,$ZDT no luck can anyone help me to convert this into required format.
Thanks,
Smythee
Comments
$Extract ($E) and $Translate ($TR) can provide a string manipulation
> set inDate="1997-08-09 10:38:39.700000000" > set outDate=$TR($E(inDate,1,19)," ","T")_"Z" > write !,outDate 1997-08-09T10:38:39Z
So steps are:
- Grab the first 19 characters
- Convert space " " to "T"
- Append a "Z" to the end
Ignore if already the case, but would also recommend familiarity with $Piece, $Select and "[" (Contains operator) . $Find can also be efficient in string searches.
Yes thank you,
Can we do that by using date function $ZDATE,$ZDATEH,$ZDATETIMEH?
w $ZDT($ZDTH(timeAndDate,3,9),3,7)
Thank you
Can you help me understand Why we used $ZDT($ZDTH(timeAndDate,3,9),3,7) 3,9 and 3,7 while converting
Thanks,
Smythee
for $ZTDH:
https://docs.intersystems.com/iris20231/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fzdatetimeh
for $ZDT:
https://docs.intersystems.com/iris20231/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fzdatetime
USER>rx1997-08-0910:38:39.700000000
USER>w$ZDTH(x,3,,9)
57199,38319.7
USER>w$zdt($ZDTH(x,3,,9),3,7)
1997-08-09T08:38:39Z
USER>w$zdt($ZDTH(x,3,,9),3,7,9)
1997-08-09T08:38:39.700000000Z
USER>