VBA DateSerial

DateSerial Function Description

The VBA Dateserial function returns a date specified by the provided year, month, and day .

VBA DateSerial Syntax

The syntax for the Dateserialfunction in VBA is:

1
DateSerial( year, month, day )

Parameters

year
Year value between 100 and 9999 that represents the year for the date.

month
Month value that represents the month of the date. 0 and negative values are allowed.

day
Day value that represents the day of the date. 0 and negative values are allowed.

Other Notes

The DateSerial function can be with 0 and negative values for the month and day parameters:

  • Values > 0 – translate to the provided month and day e.g.
    1
    2
    DateSerial 2016, 1, 1
    'Result: "2016-01-01"
  • Month values equal or below 0 – subtracts from 1 (for 0 values) or more months from the provided date (for given year and day) e.g.
    1
    2
    DateSerial 2016, 0, 1
    'Result: "2015-12-01"
  • Day values equal or below 0 – subtracts from 1 (for 0 values) to more days from the provided date (for given year and month e.g.
    1
    2
    DateSerial 2016, 1, 0
    'Result: "2015-12-31"

Example usage

The DateSerial function can be used in VBA code. Let’s look at some VBA DateSerial function examples:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
DateSerial 2015, 2, 3
'Result: "2015-02-03"
 
DateSerial 2015, 2, 3
'Result: "2015-02-03"
 
DateSerial 2016, 1, 0
'Result: "2015-12-31"
 
DateSerial 2016, 0, 0
'Result: "2015-11-30"
 
DateSerial 2016, -1, 1
'Result: "2015-11-01"