Change date format in an easier way in objectscript
I am getting the date 20201121090000 in the HL7 message, How do I convert it to 2020-11-21 09:00:00 in a easy way?
I am currently doing it by extracting the first 7 values and splitting as date and time and then adding a hyphen using substring.
Is there an easier way by using $ZDATE? or something like that?
Use $tr() in backward mode
I liked this idea
Amazing idea. Thank you Julius.
Wow, how have I not known this trick after all these years? :-)
A internet search engine can be of great help and, of course, some luck,
Carefully reading the DC is also a good source of information,

See this articles
https://community.intersystems.com/post/yet-another-use-case-translate-d...
https://community.intersystems.com/post/convert-numeric-expression202010... (last reply)
Wot, read documentation?? ;-)
I said nothing about a documentation. I don't do it even
By the way, what's the definition of an empty set?
Answer:
4(%@3%4@')6%.@"9@).4%23%#4)/.@/&@-5-03@02/'2!-%23@!.$@4(%)2@$/#5-%.4!4)/.
@Julius Kavay - a DC hack: click on a link button at the bottom of reply to copy the link in a clipboard:
and here it is : the Last reply link
@Evgeny Shvarov
Thank you, I've made a note.
don't know if this is faster but it may help Pass in your date ClassMethod testD(inDate As %String = "") As %String { s dd="" &SQL(SELECT TO_TIMESTAMP(:inDate,'YYYYMMDDHHMISS') INTO :dd) q dd }
Most of the SQL functions available with $SYSTEM.SQL
I think this can solve your problem
Hey ED Coder.
There are built in classes to manage this in a nicer way.
##class(Ens.Util.Time).ConvertDateTime() is a good starting point. For example:
Here is the filled in classmethod call for easy copy/pasting:
Set NewDate = ##class(Ens.Util.Time).ConvertDateTime(HL7Date,"%Y%m%d%H%M%S","%Y-%m-%d %H:%M:%S")
The values for each section of the date are defined by the following: https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
After seeing several solutions I got the idea to make a comparison.
The bottom line is, it's advisable to check how an algorithm (or function or method etc.) performs over another.
So try the below program snippet... you will be surprised!
Of course, the results will depend on hardware, on Cache/IRIS version and on utilisation of your system
Very cool. Certainly some cost as you work your way down the list, but for the balance of readability and performance, I prefer #2 - the $tr one.
Thank You Julius, very informative for me. Gives me an idea of the different ways I can implement the solution
Results running IRIS Container on Raspberry Pi 4 (4Gb RAM):
$e() only 1.279893
$tr() 1.281999
$e()+$zd() 1.470656
SQL/class 66.405927
I didn't include the SQL/static in my test on the RPi.
Comparison with IRIS on a Windows 10 i7 based Intel NUC machine:
$e() only .14742
$tr() .185998
$e()+$zd() .182579
SQL/class 11.305143
Mind you, the NUC cost about 15 times that of the RPi :-)
Anyway, based on a combination of the performance and coolness of technique, the $tr() one gets my vote!
Notice, by the way, the hefty performance penalty incurred by the SQL/Class option compared with the low-level ObjectScript functions ($extract and $translate).
Using $Extract will be 17 % faster (!)
Set date=20201121090000
Set newDate=$E(date,1,4)_"-"_$E(date,5,6)_"-"_$E(date,7,8)_" "_$E(date,9,10)_":"_$E(date,11,12)_":"_$E(date,13,14)
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue