Question
· Jun 23, 2023

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

Product version: Ensemble 2018.1
$ZV: Cache for Windows (x86-64) 2018.1.1 (Build 312_1_18937U) Fri Apr 26 2019 17:58:36 EDT
Discussion (5)1
Log in or sign up to continue

$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.

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>r x
1997-08-09 10: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>