# DateAdd

Returns a date to which a specified time interval has been added.

See also DateConvert, DatePart, and CreateTimeSpan.

### Syntax

    DateAdd(datepart, number, date)

##### datepart

One of the following strings:

- `yyyy` -- Year
- `q` -- Quarter
- `m` -- Month
- `y` -- Day of year
- `d` -- Day
- `w` -- Weekday
- `ww` -- Week
- `h` -- Hour
- `n` -- Minute
- `s` -- Second

##### number

Number of units of datepart to add to date (positive to get dates in the future or negative to get dates in the past).

##### date

Date/time object in the period from 100 AD to 9999 AD. Years from 0 to 29 are interpreted as 21st century values. Years 30 to 99 are interpreted as 20th century values.

### Usage

The datepart specifiers "y," "d," and "w" perform the same function -- add a certain number of days to a given date.

When passing a date/time value as a string, make sure it is enclosed in quotes. Otherwise, it is interpreted as a number representation of a date/time object, returning undesired results.

### Examples

    <!--- This example shows the use of DateAdd --->
    ...
    <CFQUERY NAME="GetMessages" DATASOURCE="cfsnippets">
    SELECT  UserName, Subject, Posted
    FROM Messages
    </CFQUERY>

    <P>This example uses DateAdd to determine when a message in
    the database will expire.  (The value selected is messages older
    than <CFOUTPUT>#value#

    <CFSWITCH EXPRESSION=#type#>
        <CFCASE VALUE="yyyy">years</CFCASE>
        <CFCASE VALUE="q">quarters</CFCASE>
        <CFCASE VALUE="m">months</CFCASE>
        <CFCASE VALUE="y">days of year</CFCASE>
        <CFCASE VALUE="w">weekdays</CFCASE>
        <CFCASE VALUE="ww">weeks</CFCASE>
        <CFCASE VALUE="h">hours</CFCASE>
        <CFCASE VALUE="n">minutes</CFCASE>
        <CFCASE VALUE="s">seconds</CFCASE>
        <CFDEFAULTCASE>years</CFDEFAULTCASE>
    </CFSWITCH>
    </CFOUTPUT>).

    <TABLE>
    <TR>
        <TD>UserName</TD>
        <TD>Subject</TD>
        <TD>Posted</TD>
    </TR>
    <CFOUTPUT query="GetMessages">
    <TR>
        <TD>#UserName#</TD>
        <TD>#Subject#</TD>
        <TD>#Posted# <CFIF DateAdd(type, value,
            posted) LT Now()>EXPIRED</CFIF></TD>
    </TR>
    </CFOUTPUT>
    </TABLE>
    ...