### DateAdd (intervalType, nIntervals, startDateTime)

Basic and Crystal syntax.

##### Arguments

intervalType is a String expression specifying the interval of time to be added. Values can be:

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

- 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.

##### Returns

A DateTime value.

##### 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

The following examples are applicable to both Basic and Crystal syntax:

`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

- This function is designed to work like the Visual Basic function of the same name.
- 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#))`

Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com