Rexx.exe Date Function Returns Wrong Year After 2000

ID: Q250611


The information in this article applies to:
  • Microsoft Windows NT Server version 4.0


SYMPTOMS

The Date() function in the Rexx.exe scripting engine returns the year 100 instead of the year 00 when you use the E, O, or U switches.


CAUSE

The problem occurs because the localtime() C library function in the Rexx.exe source code returns the year as the number of years after 1900.


RESOLUTION

To resolve this issue, modify the source code and recompile the Rexx.exe script engine to handle year 2000 and later dates.

The Rexx.exe source code is included in the Microsoft Windows NT Resource Kit CD-ROM in the \Source\Gnu\Rexx folder.

For example, here is one way you can correct the source code:

The problems are in the std_date() function found in the source file builtin.c.

The code uses two characters for the year portion of the date, and stores it in the tmdata structure by the localtime() function. However, this is incorrect. For example:


      case 'O':
         retval = Malloc(9+STRHEAD) ;
         sprintf(retval, fmt, tmdata->tm_year, tmdata->tm_mon+1, 
                           tmdata->tm_mday); 
If you change the code above to the following code, the return is 00/01/10 for today's date:

      case 'O':
         retval = Malloc(9+STRHEAD) ;
         sprintf(retval, fmt, tmdata->tm_year-100, tmdata->tm_mon+1, 
                           tmdata->tm_mday); 
To potentially work around this problem:
  1. Modify a Rexx script to accommodate this behavior. Here is a scripting example that does so.


  2. 
       say 'Modified output for date(o) function'
       x = date('o')
       y = translate(x,' ','/')
       year = word(y,1)
       month = word(y,2)
       day = word(y,3)
       x = year-100'/'month'/'day
       say x 
  3. Use one of the Rexx date options that correctly return the date, such as 'S'.


  4. Omit the use of the year portion of the date in your script.


  5. Rewrite your scripts using Windows Scripting Host (WSH).



STATUS

Microsoft has determine that this problem in the REXX.EXE source code is by design.

Additional query words:

Keywords : kbenv
Version : winnt:4.0
Platform : winnt
Issue type : kbprb


Last Reviewed: January 28, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.