This function formats a date from a specified year, month, and day.
DateSerial(year, month, day)
Returns a Variant of subtype Date.
To specify a date, such as December 31, 1991, the range of numbers for each parameter of DateSerial should be in the accepted range for the unit; that is, from 1 through 31 for days and from 1 through 12 for months. However, you also can specify relative dates for each parameter using any numeric expression that represents some number of days, months, or years before or after a certain date.
The following code example uses numeric expressions instead of absolute date numbers. In this example, DateSerial returns a date that is the day before the first day (1–1) of two months before August (8–2) of 10 years before 1990 (1990–10); in other words, DateSerial returns May 31, 1980.
DateSerial(1990
–10, 8
–2, 1
–1)
For the year parameter, values from 0 through 99 are interpreted as the years from 1900 through 1999. For all other year parameters, use a complete four-digit year, such as 1800.
When any parameter exceeds the accepted range for that parameter, it increments to the next larger unit as appropriate. For example, if you specify 35 days, it is evaluated as one month and some number of days, depending on where in the year it is applied. However, an error occurs if any single parameter is outside the range from –32,768 through 32,767. In addition, an error occurs if the date specified by the three parameters, either directly or by expression, falls outside the acceptable range of dates.