Microsoft KB Archive/77393

= BUG: DateSerial Does Not Give Error for Invalid Month or Day =

Article ID: 77393

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 1.0 Standard Edition

-



This article was previously published under Q77393



SYMPTOMS
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 &quot;Illegal function call&quot; 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.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
Page 65 of the &quot;Microsoft Visual Basic: Language Reference&quot; version 1.0 manual states the following:   &quot;...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....&quot; 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.

The following are examples of statements that will not produce errors: 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 &quot;Illegal function call&quot;. 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: kbbug kbenv kbref kbdocs kbpending KB77393

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.