The VBA DATEADD Function

Related Function:
VBA DateDiff

Description

The VBA DateAdd Function adds a time interval to a supplied date and/or time, and returns the resulting date/time.

The syntax of the DateAdd function is:

Dateadd( Interval, Number, Date )

Where the function arguments are:

Interval -

A string specifying the interval to be used. This can have any of the following values:

"d" - Days
"h" - Hours
"n" - Minutes
"m" - Months
"q" - Quarters (of a Year)
"s" - Seconds
"ww" - Weeks
"yyyy" - Years
Number - The number of intervals to add to the specified Date.
Date - The original date/time that you want to add the specified number of intervals to.


VBA DateAdd Function Examples

Example 1

' Add 32 days to the date 11/29/2015
Dim oldDate As Date
Dim newDate As Date
oldDate = #11/29/2015#
newDate = DateAdd( "d", 32, oldDate )
' newDate is now set to the date 12/31/2015

In the above example, the DateAdd function adds 32 days to the date 11/29/2015, and returns the date 12/31/2015.


Example 2

' Calculate date and time that is 27 hours after 9:00 AM on 11/29/2015
Dim oldDate As Date
Dim newDate As Date
oldDate = #11/29/2015 9:00:00 AM#
newDate = DateAdd( "h", 27, oldDate )
' newDate is now set to the date and time 11/30/2015 12:00:00 PM

In the above example, the VBA DateAdd function adds 27 hours to the date and time 11/29/2015 9:00:00 AM, and returns the result 11/30/2015 12:00:00 PM.


Example 3

' Calculate date that is 3 months after 12/31/2015
Dim oldDate As Date
Dim newDate As Date
oldDate = #12/31/2015#
newDate = DateAdd( "m", 3, oldDate )
' newDate is now set to the date 3/31/2016

In the above example, the VBA DateAdd function adds 3 months to the date 12/31/2015, and returns the resulting date 3/31/2016.