openedgeprogress-4gl

Initializing date format


I am reading birthdates from a file. They are the format 2-Aug-83, 11-Jun-03. Is there a way to read these in and change the format to the default DD/MM/YYYY? This is the idea, but it is not syntactically valid, clearly. I have found so little online on using date masks and it stumps me each time that I encounter non-default date formats in data. (I wish I could make a stronger attempt but I am at a loss on how to begin.)

Here is the idea of what I want to do:

DEFINE VARIABLE dBirthday AS DATE FORMAT "DD-MON-YY".

dBirthday = 2-AUG-80.

DISPLAY dBirthday FORMAT "DD/MM/YYYY".

Solution

  • You're probably better off by reading it às a character variable and then parsing it as an Openedge date format.

    So this

    dBirthday = 2-AUG-80.
    

    wouldn't work because it's not how the date format works. You could do something along the lines of

    dBirthday = fParseOracleDate("2-AUG-80").
    
    FUNCTION fParseOracleDate RETURNS DATE (cDate AS CHARACTER):
       DEF VAR iMonth AS INT.
       CASE ENTRY(2, cDate, '-'):
          WHEN 'Jan' THEN ASSIGN iMonth = 1.
          /* all months here */
       END CASE.
       RETURN DATE(iMonth, INT(ENTRY(1, cDate,'-')), INT(ENTRY(3, cDate, '-'))).
    END FUNCTION.
    

    Sorry for the sloppy code, typing on my phone.