Microsoft KB Archive/250611

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 08:44, 21 July 2020 by X010 (talk | contribs) (Text replacement - ">" to ">")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


Rexx.exe Date Function Returns Wrong Year After 2000

Article ID: 250611

Article Last Modified on 11/1/2006



APPLIES TO

  • Microsoft Windows NT Server 4.0 Standard Edition



This article was previously published under Q250611

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.

       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
                        
  2. Use one of the Rexx date options that correctly return the date, such as 'S'.
  3. Omit the use of the year portion of the date in your script.
  4. Rewrite your scripts using Windows Scripting Host (WSH).


STATUS

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

Keywords: kbenv kbprb KB250611