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

Last reviewed: March 20, 1998
Article ID: Q77393

The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SYMPTOMS

The DateSerial function doesn't generate an error when you use values for the month and the day arguments that are outside the ranges specified in the "Microsoft Visual Basic: Language Reference" version 1.0 manual.

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 1753 and 2078 (inclusive). You also get the error if the date specified by the three arguments either directly or indirectly evaluates to a date that is before January 1, 1753 or after December 31, 2078.

STATUS

Microsoft has confirmed this to be a bug 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

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.

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 "Illegal function call" 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

Keywords          : buglist3.00 EnvtRun RefsDoc buglist1.00 buglist2.00 kbbuglist kbenv kbtlc
Version           : 1.0 2.0 3.0
Platform          : WINDOWS
Issue type        : kbbug


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.