XL7: Dates with Two-Digit Years May Yield Unexpected Results

ID: Q136731

The information in this article applies to:

SYMPTOMS

In Visual Basic for Applications, when you use the BuiltinDocumentProperties or CustomDocumentProperties property to set a date prior to January 1, 1980, or after December 31, 1999, and if you use two digits for the year (that is, you use the "mm/dd/yy" format), a date value you do not expect may be returned. For example, when you run the following procedure

   Sub Test()
      ThisWorkbook.BuiltinDocumentProperties("Last Save Time") = "1/1/04"
      MsgBox ThisWorkbook.BuiltinDocumentProperties("Last Save Time").Value
   End Sub

a message box displays the value "11/30/79" instead of "1/1/04."

CAUSE

The mm/dd/yy date sequence is a carry-over from the original 8-bit number storage design of the hardware and software from the first PC design. In the original design, the default first date was 01/01/80 and no allowance was made for dates beyond 12/31/99. Any value outside the old range is not recognized as valid.

Note that if you enter a date using a two-digit year in an Excel 7.0 worksheet, Excel uses the following centuries.

   Two-digit        Century used
   year typed
   ---------------------------------

   00-19            21st (year 2000)
   20-99            20th (year 1900)

WORKAROUND

If a date is outside the old default range of 01/01/80 to 12/31/99, add the century to the date; that is, use the form "mm/dd/yyyy."

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/supportnet/refguide/ 

For example, when you use the following lines in your procedure

   var1 = "12/31/1979"
   ThisWorkbook.BuiltinDocumentProperties("Last Save Time") = "1/1/2004"

a fully qualified date will be evaluated (this date it is expressed without system interpolation).

NOTE: The syntax forms mm/dd/yy and mm/dd/yyyy refer to the actual cell or variable contents; they do not refer to formatting applied to cells on a worksheet.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

For additional information on dates in Microsoft Excel, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q164406
   TITLE     : XL: How Microsoft Excel Works with Two-Digit Year Numbers

Additional query words: 7.00
Keywords          : kbprg xlwin 
Version           : 7.00
Platform          : WINDOWS

Last Reviewed: May 17, 1999