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

Last reviewed: September 11, 1997
Article ID: Q136731
The information in this article applies to:
  • Microsoft Excel for Windows 95, versions 7.0

SYMPTOMS

In Visual Basic, Applications Edition, 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), an incorrect date value may result. 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. Software programs that use the standard system settings for speed still refer to these stored values. Any value outside the old range is not recognized as valid by the system. As a result, you may receive incorrect answers or general protection (GP) faults.

WORKAROUND

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

Microsoft provides examples of Visual Basic procedures 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 Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

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(s) 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 PgmOthr xlwin kbcode kbprb
Version : 7.00
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.