DATE function

Posted by Roger Blanchard on 18-Jan-2018 11:25

OE 11.7

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

All Replies

Posted by Peter Judge on 18-Jan-2018 11:33

 

Posted by Roger Blanchard on 18-Jan-2018 11:38

I must be missing something. Why would that produce a 3-digit year beginning with a 0?

If I use DATE ("01/26/66") it returns correctly 01/26/66.

Posted by Matt Gilarde on 18-Jan-2018 11:38

Yes, it's related to -yy (which defaults to 1950). If the date falls outside of the 100-year window ranging from -yy to -yy + 99 (1950 to 2049) the century is included in the date so you know that it's not 1966, to use your example. For dates in the first century only one zero is used which is probably a bug but given that there aren't many practical uses for dates in the first century in OpenEdge applications it's not something we're likely to fix.

Posted by Matt Gilarde on 18-Jan-2018 11:42

I realized that my answer doesn't make sense for your example. DATE(1, 26, 0066) would be displayed as "01/26/066" but DATE(1, 26, 66) shows as "01/26/66". Are you using a non-default value for -yy?

Posted by Roger Blanchard on 18-Jan-2018 11:45

Wow, I was scratching my head with your prior answer.

I use the default -yy.

I even tried using SESSION:YEAR-OFFSET = 1950.

What is odd is the if you pass the string "01/26/66" to the DATE function it works just fine.

Posted by Matt Gilarde on 18-Jan-2018 11:48

Are you testing this in the Procedure Editor with no startup parameters? What platform are you using?

Posted by Håvard Danielsen on 18-Jan-2018 11:50

First century has to be shown as 099 to avoid ambiguity with whatever century is defined by -yy..

When you convert to string -yy is already applied..

Posted by Roger Blanchard on 18-Jan-2018 11:52

Windows with 32-bit and 64-bit doing same thing.

I tested in PDSOE as well as web client runtime.

Posted by Matt Gilarde on 18-Jan-2018 11:55

What does MESSAGE SESSION:STARTUP-PARAMETERS show?

Posted by Håvard Danielsen on 18-Jan-2018 11:56

continuing ...  and the 3rd parameter of the DATE is an integer and cannot care about -yy.

Posted by jquerijero on 18-Jan-2018 11:56

What control are you using to display the date (.NET control or ABL control)? Century setting for the Windows OS is typically different from Progress run-time setting.  

Posted by Roger Blanchard on 18-Jan-2018 12:02

ABL MESSAGE VIEW-AS ALERT-BOX.

Posted by Roger Blanchard on 18-Jan-2018 12:22

I guess Havard says this is working correctly...

We found this while testing our DB replication where the primary key contains a date field. We were storing the date in a char field with just STRING(date). We modified this to STRING(date,"99/99/9999") and we now get a valid date.

Posted by Akshay Guleria on 19-Jan-2018 01:18

I believe this is actually a problem. Just consider the below example and see how the conversion of date behaves when the separator changes. 

[mention:9e4ee96fac634b8f91b580e1fb4f7e71:e9ed411860ed4f2ba0265705b8793d05] - Do you know if someone can check the DATE function implementation and find why the results differ when the separator is ","

Note: Code executed https://abldojo.services.progress.com

Code

DISP 'Separator is `,` =>'.
DISPLAY INT(DATE(01,26,66)) STRING(DATE(01,26,66)) DATE(01,26,66) FORMAT "99/99/9999" SKIP.

DISP 'Separator is `.` =>'.
DISPLAY INT(DATE(01.26.66)) STRING(DATE(01.26.66)) DATE(01.26.66) FORMAT "99/99/9999" SKIP.

DISP 'Separator is `/` =>'.
DISPLAY INT(DATE(01/26/66)) STRING(DATE(01/26/66)) DATE(01/26/66) FORMAT "99/99/9999" SKIP.

Result:

Separator is `,` =>  1,745,191 26/01/06 26/01/0066
Separator is `.` =>  2,439,153 26/01/66 26/01/1966
Separator is `/` =>  2,439,153 26/01/66 26/01/1966

Posted by Patrick Tingen on 19-Jan-2018 01:56

And the outcome is 100% correct. It is not a matter of separator, it is a matter of datatype. When you pass in 01,26,66 you actually pass in 3 integers. When you pass in 01.26.66 or 01/26/66 you pass in a date.

Consider the possible ways to call the DATE function:

  • DATE ( month , day , year )
  • DATE ( string )
  • DATE ( integer-expression )
  • DATE ( datetime-expression )

when using DATE(1,26,66) you get (and should get!) 26 january of the year 66. Not 1966. If you wanted that you should have used DATE(1,2,6,1966) instead. 

Funny though is that it is possible to notate a date with dots instead of slashes. Didn't know that. 

Posted by Simon L. Prinsloo on 19-Jan-2018 02:10

I agree with @Patrick [mention:e666fffb14004b29b4bad87b731999a8:e9ed411860ed4f2ba0265705b8793d05]  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.

Posted by goo on 19-Jan-2018 04:12

Thanks for clarifying  😊 I didn’t know that either…
 

Posted by Roger Blanchard on 19-Jan-2018 07:34

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

Posted by George Potemkin on 19-Jan-2018 09:04

> 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.

This thread is closed