Description
A DateTime value.
Arguments
intervalType is a String expression specifying the interval of time to be added.
nIntervals is a Number or numeric expression specifying the number of intervals to be added. It can be positive (to get date-times in the future) or negative (to get date-times in the past).
startDateTime is the DateTime value to which the intervals are to be added.
Argument values
IntervalType values can be one of the following:
| |
---|
| |
| Quarter (the result is 1, 2, 3 or 4) |
| Month (the result is from 1 to 12) |
| Day of year (1 to 365 or 366 in a leap year) |
| Day part of the date (1 to 31) |
| Day of week (1 to 7 with the result depending on firstDayOfWeek) |
| Week of year (1 to 53 with firstDayOfWeek and firstWeekOfYear determining the exact days of the first calendar week of the year) |
| Extracts the hour part of the given DateTime (0 to 23) |
| |
| |
Action
DateAdd returns a DateTime value to which a specified number of time intervals have been added.
Typical use
DateAdd is used to add intervals of time to a DateTime. Its main feature is that the DateTime returned will always be valid. For example, DateAdd 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 DateAdd with the "d" parameter. However, DateAdd also handles other types of intervals such as adding months or hours to a DateTime.
Examples
DateAdd("d", -32, #Sept 28, 1999#)
Returns the DateTime value for August 27, 1999.
DateAdd ("m", 1, #1/31/1996#)
Returns the DateTime value for February 29, 1996. Notice that DateAdd will not return the invalid value February 31, 1996.
DateAdd ("q", 17, #Sept 28, 1999#)
Returns the DateTime value for December 28, 2003.
DateAdd ("h", -400, #Sept 28, 1999#)
Returns the DateTime value for September 11, 1999 8:00 AM. In other words, this is the result of subtracting 400 hours from September 28, 1999 12:00 AM.
Comments
To add days to a date-time, you can use any of the interval type parameters "y", "d" or "w". They all have the same effect for DateAdd.
DateAdd returns a DateTime value and not a Date value. However, you may need to convert this DateTime value to a Date value in certain situations (such as if you wanted to assign the value returned by DateAdd to a Date type variable). To convert to a Date value, use DateAdd in combination with the CDate type conversion function. For example, the following returns the Date value for October 6, 1997:
CDate(DateAdd("yyyy", -2, #October 6, 1999#))