Dates with Two-Digit Years May Yield Unexpected Results (136731)



The information in this article applies to:

  • Microsoft Excel for Windows 95

This article was previously published under Q136731

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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. 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:

302768 How Microsoft Excel works with two-digit year numbers


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbProgramming KB136731