The DateSerial function in VBA returns a Date from a supplied year, month, and day number.

Syntax

Parameter

Year (required) – This parameter represents an integer signifying the year.

Month (required) – This parameter represents an integer signifying the month. If the Integer values are less than 1 or greater than 12, the values are interpreted as:

  • -1 – November of the previous year
  • 0 – November of previous year
  • 13 – January of the following year
  • 14 – February of the following year

Day (required) – This parameter represents an integer signifying the day of the month. If the integer values less are than 1 or greater than the number of days in the current month are interpreted as follows:

  • -1 – It signifies the second to the last day of the previous month
  • 0 – It signifies the last day of the previous month.
  • Days in current month + 1 – It signifies the first day of the following month
  • Days in current month + 2 – It signifies the second day of the following month.

Return

This function returns a Date from a supplied year, month, and day number.

Example 1

Output

7/1/2020
7/1/2020
VBA DateSerial Function

Example 2

Output

12/31/2020
1/31/2021

Example 3

Output

12/1/2020
1/1/2021
VBA DateSerial Function

Pin It on Pinterest

Share This