<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>DATEADD</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">DATEADD</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Adds units of time to a date.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
A date/time object.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Date and time functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>DateAdd(&quot;datepart&quot;, number, &quot;date&quot;)
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
DateConvert, DatePart, CreateTimeSpan
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion MX&#160;6.1: Added the datepart character L or l to represent milliseconds.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
The datepart specifiers y, d, and w add a number of days to a date.
</p>

<p>
When passing a date/time object as a string, you must enclose it in quotation marks. Otherwise, it is interpreted as a numeric representation of a date/time object.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span><pre>&lt;!--- This example shows the use of DateAdd ---&gt;
&lt;cfparam name=&quot;value&quot; default=&quot;70&quot;&gt;
&lt;cfparam name=&quot;type&quot; default=&quot;m&quot;&gt;

&lt;!--- if numbers passed, then use those ---&gt;
&lt;cfif IsDefined(&quot;form.value&quot;)&gt;
   &lt;cfset value = form.value&gt;
&lt;/cfif&gt;
&lt;cfif IsDefined(&quot;form.type&quot;)&gt;
   &lt;cfset type = form.type&gt;
&lt;/cfif&gt;


&lt;cfquery name=&quot;GetMessages&quot; datasource=&quot;cfdocexamples&quot;&gt;
SELECT&#160;&#160;&#160;UserName, Subject, Posted
FROM&#160;&#160;&#160;&#160;&#160;Messages
&lt;/cfquery&gt;

&lt;p&gt;This example uses DateAdd to determine when a message in
the database will expire. Currently, messages older
than &lt;cfoutput&gt;#value#&lt;/cfoutput&gt;

&lt;cfswitch expression=&quot;#type#&quot;&gt;
   &lt;cfcase value=&quot;yyyy&quot;&gt;years&lt;/cfcase&gt;
   &lt;cfcase value=&quot;q&quot;&gt;quarters&lt;/cfcase&gt;
   &lt;cfcase value=&quot;m&quot;&gt;months&lt;/cfcase&gt;
   &lt;cfcase value=&quot;y&quot;&gt;days of year&lt;/cfcase&gt;   
   &lt;cfcase value=&quot;w&quot;&gt;weekdays&lt;/cfcase&gt;   
   &lt;cfcase value=&quot;ww&quot;&gt;weeks&lt;/cfcase&gt;   
   &lt;cfcase value=&quot;h&quot;&gt;hours&lt;/cfcase&gt;   
   &lt;cfcase value=&quot;n&quot;&gt;minutes&lt;/cfcase&gt;   
   &lt;cfcase value=&quot;s&quot;&gt;seconds&lt;/cfcase&gt;      
   &lt;cfdefaultcase&gt;years&lt;/cfdefaultcase&gt;
&lt;/cfswitch&gt;
 are expired.

&lt;table&gt;
&lt;tr&gt;
   &lt;td&gt;UserName&lt;/td&gt;
   &lt;td&gt;Subject&lt;/td&gt;
   &lt;td&gt;Posted&lt;/td&gt;
&lt;/tr&gt;
&lt;cfoutput query=&quot;GetMessages&quot;&gt;
&lt;tr&gt;
   &lt;td&gt;#UserName#&lt;/td&gt;
   &lt;td&gt;#Subject#&lt;/td&gt;
   &lt;td&gt;#Posted# &lt;cfif DateAdd(type, value, posted) LT Now()&gt;&lt;font 
color=&quot;red&quot;&gt;EXPIRED&lt;/font&gt;&lt;/cfif&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/cfoutput&gt;
&lt;/table&gt;

&lt;cfform action=&quot;#CGI.Script_Name#&quot; method=&quot;post&quot;&gt;

Select an expiration value:
&lt;cfinput type=&quot;Text&quot; name=&quot;value&quot; value=&quot;#value#&quot; message=&quot;Please enter whole 
numbers only&quot; validate=&quot;integer&quot; required=&quot;Yes&quot;&gt;
&lt;select name=&quot;type&quot;&gt;
   &lt;option value=&quot;yyyy&quot;&gt;years
   &lt;option value=&quot;m&quot; selected&gt;months
   &lt;option value=&quot;d&quot;&gt;days
   &lt;option value=&quot;ww&quot;&gt;weeks            
   &lt;option value=&quot;h&quot;&gt;hours
   &lt;option value=&quot;n&quot;&gt;minutes
   &lt;option value=&quot;s&quot;&gt;seconds
&lt;/select&gt;
   
&lt;input type=&quot;Submit&quot; value=&quot;Submit&quot;&gt;
&lt;/cfform&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="DATEPART">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">DATEPART</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>String:</p><ul>

<li>yyyy: Year</li>

<li>q: Quarter</li>

<li>m: Month</li>

<li>y: Day of year</li>

<li>d: Day</li>

<li>w: Weekday</li>

<li>ww: Week</li>

<li>h: Hour</li>

<li>n: Minute</li>

<li>s: Second</li>

<li>l: Millisecond</li>
</ul>


  </td>
  </tr>
  </table>
</div>
<div id="NUMBER">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">NUMBER</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>Number of units of datepart to add to date (positive, to get dates in the future; negative, to get dates in the past). Number must be an integer.</p>

  </td>
  </tr>
  </table>
</div>
<div id="DATE">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">DATE</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>Date/time object, in the range 100 AD-9999 AD.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
