Returns a DateTime value to which a specified number of time intervals have been added.
This function is used to add interval of time to a DateTime. Its main feature is that the DateTime returned will always be valid. For example, the function takes into account such factors as the number of days in a month and leap years. If you want to add or subtract days to a DateTime, you could use the addition and subtraction operators instead of the function with the "d" parameter. However, this function also handles other types of intervals such as adding months or hours to a DateTime.
Parameters
| IntervalType value | Description |
|---|---|
| yyyy | Year |
| q | Quarter (3-month period) |
| m | Month |
| y | Day of year |
| d | Day |
| w | Weekday |
| ww | Week (7-day period) |
| h | Hour |
| n | Minute |
| s | Second |
Return value
A DateTime value.
Examples
DateAdd("d",-32,ToDateTime(1999,9,28)) - Returns the DateTime value for 1999-8-27 00:00:00.DateAdd("m",1,ToDateTime(1996,1,31)) - Returns the DateTime value for 1996-2-29 00:00:00. Notice that DateAdd will not return the invalid value 1996-2-31 00:00:00.DateAdd("q",17,ToDateTime(1999,9,28)) - Returns the DateTime value for 2003-12-28 00:00:00.DateAdd("h",-400,ToDateTime(1999,9,28)) - Returns the DateTime value for 1999-9-11 08:00:00. In other words, this is the result of subtracting 400 hours from 1999-9-28 00:00:00.Notes:
ToDate(DateAdd("yyyy",-2,ToDateTime(1999,10,6)))