Answered Whats the best way to convert and ISO-DATE to a date datatype?

Cecil

19+ years progress programming and still learning.
I know of two ways to convert an ISO-DATE formatted string into a date datatype and I think both sucks! What is the best approach to importing ISO-DATE formatted strings into a date datatype. Is there some sort of secret Openedge function that I don't know about?

Code:
DEFINE VARIABLE isoDateFormatted AS CHARACTER   NO-UNDO.

DEFINE VARIABLE DATE        AS DATE        NO-UNDO.
DEFINE VARIABLE dateYear    AS INTEGER     NO-UNDO.
DEFINE VARIABLE dateMonth   AS INTEGER     NO-UNDO.
DEFINE VARIABLE dateDay     AS INTEGER     NO-UNDO.


isoDateFormatted = "1980-12-25".

IF NUM-ENTRIES(isoDateFormatted, '-') EQ 3 THEN
    ASSIGN
        dateYear  = INTEGER(ENTRY(1, isoDateFormatted, '-'))   
        dateMonth = INTEGER(ENTRY(2, isoDateFormatted, '-'))   
        dateDay   = INTEGER(ENTRY(3, isoDateFormatted, '-'))
        DATE      = DATE(dateMonth, dateDay, dateYear).
        
MESSAGE isoDateFormatted SKIP
        DATE
        VIEW-AS ALERT-BOX INFO.


Code:
DEFINE VARIABLE isoDateFormatted         AS CHARACTER   NO-UNDO.
DEFINE VARIABLE DATE                     AS DATE        NO-UNDO.
DEFINE VARIABLE currentSessionDateFormat AS CHARACTER   NO-UNDO.

isoDateFormatted = "1980-12-25".

/** Session Date-format is DMY **/
currentSessionDateFormat = SESSION:DATE-FORMAT.

SESSION:DATE-FORMAT = "ymd":U.

/** IF THE DATE FUNCTIONS ERRORS, THE SESION DATE-FORMAT IS THEN SCREWED. **/
DATE = DATE(isoDateFormatted).

SESSION:DATE-FORMAT = currentSessionDateFormat.   

MESSAGE isoDateFormatted SKIP
        DATE
        VIEW-AS ALERT-BOX INFO.
 

Cecil

19+ years progress programming and still learning.
Just to expand the code a bit better for others to understand.

Code:
 DEFINE VARIABLE daDate     AS DATE        NO-UNDO.
 DEFINE VARIABLE chISODate  AS CHARACTER   NO-UNDO.
 
 chISODate = "1969-12-25".
 
 /** Convert ISO date to date datatype.**/
 daDate = OpenEdge.Core.TimeStamp:ToABLDateFromISO(chISODate).
 
 MESSAGE
    "ISO-DATE:" chISODate SKIP
    "DATE:" STRING(daDate, "99/99/9999") SKIP
    "DATE-FORMAT:" SESSION:DATE-FORMAT
    VIEW-AS ALERT-BOX BUTTON OK.

1519798203532.png
 
Top