DateSerial Does Not Give Error for Invalid Month or Day

ID Number: Q77393

1.00

WINDOWS

Summary:

The DateSerial function doesn't generate an error when you use values

for the month and the day arguments outside the ranges specified in

the "Microsoft Visual Basic: Language Reference" version 1.0 manual.

In addition, you can use a numeric expression for each argument

representing the number of days, months, or years before or after a

certain date.

However, you 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.

This information applies to Microsoft Visual Basic programming system

version 1.0 for Windows.

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

Additional reference words: 1.00