# DateSerial
{: .no_toc }

Returns a **Variant** (**Date**) for a specified year, month, and day.

Syntax: **DateSerial** ( *year*, *month*, *day* )

*year*
: *required* **Integer**. Number between 100 and 9999, inclusive, or a numeric expression.

*month*
: *required* **Integer**. Any numeric expression.

*day*
: *required* **Integer**. Any numeric expression.

To specify a date, such as December 31, 1991, the range of numbers for each **DateSerial** argument should be in the accepted range for the unit (1--31 for days, 1--12 for months). Relative dates can also be specified for each argument by 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. The **DateSerial** function returns a date that is the day before the first day (`1 - 1`), two months before August (`8 - 2`), 10 years before 1990 (`1990 - 10`) --- in other words, May 31, 1980.

When any argument exceeds the accepted range, 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. If any single argument is outside the range -32,768 to 32,767, an error occurs.

Two-digit years for the *year* argument are interpreted based on user-defined machine settings. The default settings are that values between 0 and 29 are interpreted as the years 2000--2029, and values between 30 and 99 are interpreted as the years 1930--1999. For all other *year* arguments, use a four-digit year.

If the [**Calendar**](/tB/Modules/DateTime/Calendar.md) property setting is Gregorian, the supplied value is assumed to be Gregorian. If the setting is Hijri, the supplied value is assumed to be Hijri, and two-digit *year* values between 0 and 99 are interpreted as the years 1400--1499.

### Common Errors

| Error | When |
|---|---|
| [5 (`&H5`)](/Reference/Run-time-Errors.md#5), *Invalid procedure call or argument* | the date is before January 1, 100 or after December 31, 9999 |
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *year*, *month* or *day* is **Null** |

### Example

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

```tb check_build
Dim MyDate
MyDate = DateSerial(1969, 2, 12)    ' Returns February 12, 1969.
```

### See Also

- [DateValue](/tB/Modules/DateTime/DateValue.md), [Day](/tB/Modules/DateTime/Day.md), [Month](/tB/Modules/DateTime/Month.md), [Year](/tB/Modules/DateTime/Year.md) functions
