Question
· Mar 12, 2019

String to date

I am trying to convert a string to date but can not get it to work I have  function that I would like to take in a date string and covert it to date object

here is the ezample so far can not get it to work any help appreciated 

 

set p="12/03/2019"
 
w $System.SQL.TODATE(p,"YYYY-MM-DD")
 
<ILLEGAL VALUE>todate+32^%qarfunc

if I try this still get the wrong value returned

set p="12/03/2019" 
w $ZDATE(p,3)
1841-01-12
Discussion (6)2
Log in or sign up to continue

If you need to reorder a given set of characters (as above, from "12/03/2019" to "2019-03-12") then the $translate(...) function, used in "backward-mode" is your best friend.

set p="12/03/2019"
write $tr("abcd-ef-gh","ef/gh/abcd",p) --> 2019-12-03

Your gain: 50% of speed.

Nota bene

(1) $translate(inputdata, fromChars, toChars) --> outputdata
(2) $translate(toSequence, fromSequence, inputdata) --> outputdata

Where (1) is the Forward-Mode (the regular usage) and (2) the Backward-Mode