XL7: Dates with Two-Digit Years May Yield Unexpected ResultsLast reviewed: September 11, 1997Article ID: Q136731 |
The information in this article applies to:
SYMPTOMSIn 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 Suba message box displays the value "11/30/79" instead of "1/1/04."
CAUSEThe 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.
WORKAROUNDIf 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.
STATUSMicrosoft 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 INFORMATIONFor 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |