DATE function - Forum - OpenEdge Development - Progress Community
 Forum

DATE function

This question is not answered

OE 11.7

Does anyone know why DATE (01,26,66) would return 01/26/066 instead of 01/26/66?

All Replies
  • I agree with @Patrick  in that this is expected.

    My reason is as follows:

    In the case of DATE( month, day, year) you are not working with a date, but with three integers. The third integer must be used as is, otherwise there will be no way to use that format to obtain a date in the first century.

    -yy applies only to dates REPRESENTED without a century and has most likely started out as a method to simplify data capturing by allowing for the omission of the century.

    If the system did not work as it is now, the following code would malfunction.

    DEF VAR dd  AS INT  NO-UNDO.
    DEF VAR mm  AS INT  NO-UNDO.
    DEF VAR yy  AS INT  NO-UNDO.
    DEF VAR dte AS DATE NO-UNDO. 
    
    ASSIGN
      dte = 01/26/066
      dd  = DAY(dte)
      mm  = MONTH(dte)
      yy  = YEAR(dte)
      .
    
    MESSAGE DATE(mm, dd, yy) VIEW-AS ALERT-BOX.
    

    As it is today, the DATE function would bring us back to the original date, regardless of the century of the date.

    Simon L Prinsloo

    www.vidisolve.com

  • Thanks for clarifying  😊 I didn’t know that either…
     
  • I would expect the year to be 66 just not 066.

  • > I would expect the year to be 66 just not 066.

    Your expectation is correct: YEAR(DATE (01,26,66)) returns 66.

    But 66 AD can't be displayed using "99/99/99":

    STRING(DATE (01,26,66), "99/99/99")

    ** Value 26/01/066 cannot be displayed using 99/99/99. (74)

    The same case as DATE (01,26,10066). It will not be displayed as 01/26/66.

    Both years are out of the 100‑year period specified by the -yy.

    But try this:

    SESSION:YEAR-OFFSET = 0.
    MESSAGE DATE(01,26,66) VIEW-AS ALERT-BOX.