DateSerial Function

Description

Returns a date for a specified year, month, and day.

Syntax

DateSerial(year,month,day)

The DateSerial function syntax has these named-argument parts:

Part

Description

year

Number between 100 and 9999, inclusive, or a numeric expression.

month

Number between 1 and 12, inclusive, or a numeric expression.

day

Number between 1 and 31, inclusive, or a numeric expression.


Remarks

To specify a date, such as December 31, 1991, the range of numbers for each DateSerial argument should be in the normally accepted range for the unit; that is; 1-31 for days and 1-12 for months. However, you can also specify relative dates for each argument using any numeric expression that represents some number of days, months, or years before or after a certain date.

The following example uses numeric expressions instead of absolute date numbers. Here the DateSerial function 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, May, 31, 1980.


DateSerial(1990 - 10, 8 - 2, 1 - 1)

For the year argument, values between 0 and 99, inclusive, are interpreted as the years 1900-1999. For all other year arguments, use a complete four-digit year (for example, 1800).

If the date specified by the three arguments, either directly or by expression, falls outside the acceptable range of dates, an error occurs.

See Also

Date Function, Date Statement, DateValue Function, Day Function, Month Function, Now Function, TimeSerial Function, TimeValue Function, Weekday Function, Year Function.

Example

This example uses the DateSerial function to return the date for the specified year, month and day.


' MyDate contains the date for February 12, 1969.
MyDate = DateSerial(1969, 2, 12)    ' Return a date.