DateSerial
DateSerial
function to format a date from a
specified year, month and day.The function DateSerial
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. |
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. You
also can specify relative dates for each parameter. Use 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. It 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 a parameter exceeds the accepted range for that parameter, it increments to the next larger unit as appropriate. For example, 35 days 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.
Example
This example returns "03/02/2016":
DateSerial(2016,2,3)
This example returns "29/02/2016":
DateSerial(2016,2,3+26)
This example returns "31/01/2016":
DateSerial(2016,2,3-3)
The format of the date returned by the function depends on the system locale.