The information in this article applies to:
SYMPTOMS
The DateSerial function can seem to return unanticipated results using
years represented by numeric expressions. For example, the following
evaluates to 1/1/100 and not 1/1/00 or 1/1/2000 because 99 + 1 or 100 is a
valid full size date:
CAUSE
Visual Basic documentation gives the following rule concerning year
arguments used by the DateSerial function:
For the year argument, values between 0 and 29, inclusive, are interpreted as the years 2000-2029. Values between 30 and 99, inclusive, are interpreted as the years 1930-1999. This rule only applies to year arguments represented with 1 or 2 digits. This can sometimes produce results that may not be anticipated. For example, in the following line of code the year is actually 100, which is a valid 3 digit value in the range of 100 to 9999: DateSerial(99 + 1, 1, 1) Therefore, DateSerial correctly returns the date 1/1/100. In this case DateSerial will not return 1/1/00 or 1/1/2000. This type of behavior can occur whenever the numeric expression in the year argument evaluates to a year having more than 2 digits. RESOLUTION
There are several ways to get the desired result (1/1/2000) using years
passed as numeric expressions. One way would be to use DateSerial with the
full 4 digit year. This example returns 1/1/00:
DateSerial(1999 + 1, 1, 1) DateSerial can also be used in conjunction with the year function. This example also returns 1/1/00: DateSerial(Year(#1/1/99#)+1, Month(#1/1/99#), Day(#1/1/99#)) In addition to the DateSerial function, the DateAdd or DateDiff functions can also be used. The following example also returns 1/1/00: DateAdd("yyyy", 1, "1/1/99") MORE INFORMATIONSteps to Reproduce Behavior
Keywords : kbGrpVB |
Last Reviewed: January 5, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |