BUG: DateSerial Does Not Give Error for Invalid Month or DayID: Q77393
|
The DateSerial function doesn't generate an error when you use values for
the month and the day arguments that are outside the range of dates
recognized by Visual Basic.
You can use a numeric expression for each argument representing the number
of days, months, or years before or after a certain date. But you will get
an "Illegal function call" error message if you use a value for the year
that is not between the range of dates recognized by Visual Basic. You also
get the error if the date specified by the three arguments either directly
or indirectly evaluates to a date outside the range of recognized dates.
Visual Basic 1.0 recognizes dates in the range January 1, 1753 through
December 31, 2078. Visual Basic 2.0 and 3.0 recognize dates in the range
January 1, 100 through December 31, 9999.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
Page 65 of the "Microsoft Visual Basic: Language Reference" version 1.0 manual states the following:
"...the range of numbers for each DateSerial argument should conform to
the accepted range of values for the unit. These values are 1 to 31 for
days, and 1 through 12 for months. You can also specify relative dates
for each argument by using numeric expressions representing the number
of days, months, or years before or after a certain date...."
You can actually have values outside these ranges for the month and day
argument and Visual Basic will not give an error. For example, a value of 0
for the day evaluates to the last day of the previous month. A value of 13
for the month translates to the first month (January) of the next year.
x# = DateSerial(63,7,12) 'evaluates to July 12, 1963
x# = DateSerial(63,13,5) 'evaluates to January 5, 1964
x# = DateSerial(63,7,33) 'evaluates to August 2, 1963
x# = DateSerial(63,10,-1) 'evaluates to September 29, 1963
x# = DateSerial(63,-1,5) 'evaluates to November 5, 1962
The following statements will generate an "Illegal function call". With
Visual Basic 1.0, the following statements will generate this error because
they produce dates before January 1, 1753 and after December 31, 2078:
x# = DateSerial(1750,3,1) 'evaluates to March 1, 1750
x# = DateSerial(2078,12,40) 'evaluates to January 9, 2079
x# = DateSerial(1753,-5,20) 'evaluates to July 20, 1752
The following statements will generate this error with Visual Basic 2.0 and
3.0 because they produce dates before January 1, 100 and after December 31,
9999:
x# = DateSerial(9999,12,32) 'evaluates to January 1, 10000
x# = DateSerial (100, 0, 1) 'evaluates to December 1, 99
Additional query words:
Keywords : kbenv kbref kbtlc kbDocs kbVBp300 kbDSupport kbvbp200 kbvbp100
Version : WINDOWS:1.0,2.0,3.0
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: June 21, 1999