DateSerial
Purpose
This function formats a date from a specified year, month, and day. It returns a Variant of subtype Date.
Syntax
DateSerial(year, month, day)
Argument | Description |
---|---|
year | Number from 100 through 9,999 or a numeric expression. |
month | Any numeric expression. |
day | Any numeric expression. |
Description
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.
DateSerial(1990-10, 8-2,
1-1)
returns 31/05/1980
This 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.
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, then it is evaluated as one month and some number of days, depending on where in the year it is applied.
An error occurs if any single parameter is outside the range from -32,768 through 32,767. Additionally, an error occurs if the date specified by the three parameters, either directly or by expression, falls outside the acceptable range of dates.
Examples
Function | Result |
---|---|
DateSerial(2016,2,3) | 03/02/2016 |
DateSerial(2016,2,3+26) | 01/03/2016 |
DateSerial(2016,2,3-3) | 31/01/2016 |
The format of the date returned by the function will depend on your system locale.