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:
Where the function arguments are:
Interval | - |
A string specifying the interval to be used. This can have any of the following values:
|
||||||||||||||||||||||||
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. |
' Add 32 days to the date 11/29/2015
Dim oldDate As Date
Dim newDate As Date
oldDate = #11/29/2015#
' newDate is now set to the date 12/31/2015
newDate = DateAdd( "d", 32, oldDate ) |
In the above example, the DateAdd function adds 32 days to the date 11/29/2015, and returns the date 12/31/2015.
' 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 is now set to the date and time 11/30/2015 12:00:00 PM
newDate = DateAdd( "h", 27, oldDate ) |
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.
' Calculate date that is 3 months after 12/31/2015
Dim oldDate As Date
Dim newDate As Date
oldDate = #12/31/2015#
' newDate is now set to the date 3/31/2016
newDate = DateAdd( "m", 3, oldDate ) |
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.