<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>DATEDIFF</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">DATEDIFF</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>
Determines the integer number of units by which date1 is less than date2.
</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 number of units, of type datepart.
</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>DateDiff(&quot;datepart&quot;, &quot;date1&quot;, &quot;date2&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>
DateAdd, 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&#160;MX: 
</p>
<ul>

<li>Changed how negative date differences are calculated: this function calculates negative date differences correctly; its output may be different from that in earlier releases. </li>

<li>Changed the w and ww masks; they determine the number of full weeks between the two dates.</li>
</ul>
    </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 DateDiff function determines the number of complete datepart units between the two dates; for example, if the datepart parameter is &quot;m&quot; and the dates differ by 55 days, the function returns 1.
</p>

<p>
Enclose string constant dates in quotation marks. If the text contains only numbers (such 1932), and is not surrounded by quotation marks, ColdFusion interprets it as a date/time object, resulting in an incorrect value.
</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;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;cfif IsDefined(&quot;form.date1&quot;) and IsDefined(&quot;form.date2&quot;)&gt;

   &lt;cfif IsDate(form.date1) and IsDate(form.date2)&gt;
   
      &lt;p&gt;This example uses DateDiff to determine the difference
      in    
      &lt;cfswitch expression = &quot;#form.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&lt;/cfcase&gt;   
         &lt;cfcase value=&quot;d&quot;&gt;days&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;
          dateparts between date1 and date2.
      
      &lt;cfif DateCompare(&quot;#form.date1#&quot;,&quot;#form.date2#&quot;) is not 0&gt;
      &lt;p&gt;The difference is &lt;cfoutput&gt;#Abs(DateDiff(type, form.date2, 
form.date1))#&lt;/cfoutput&gt;
      &lt;cfswitch expression = &quot;#form.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&lt;/cfcase&gt;   
         &lt;cfcase value=&quot;d&quot;&gt;days&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;.
      &lt;cfelse&gt;
      &lt;p&gt;The two dates are equal!  Try changing one of the values ...
      &lt;/cfif&gt;
   
   &lt;cfelse&gt;
   &lt;p&gt;Please enter two valid date/time values, formatted like this:
   &lt;cfoutput&gt;#DateFormat(Now())#&lt;/cfoutput&gt;   
   &lt;/cfif&gt;   

&lt;/cfif&gt;
&lt;form action=&quot;index.cfm&quot; method=&quot;post&quot;&gt;

&lt;pre&gt;
Date 1
&lt;input type=&quot;Text&quot; name=&quot;date1&quot; value=&quot;&lt;CFOUTPUT&gt;#DateFormat(Now())#&lt;/
CFOUTPUT&gt;&quot;&gt;
Date 2
&lt;input type=&quot;Text&quot; name=&quot;date2&quot; value=&quot;&lt;CFOUTPUT&gt;#DateFormat(Now())#&lt;/
CFOUTPUT&gt;&quot;&gt;
What kind of unit to show difference?
   &lt;select name=&quot;type&quot;&gt;
      &lt;option value=&quot;yyyy&quot; selected&gt;years
      &lt;option value=&quot;q&quot;&gt;quarters
      &lt;option value=&quot;m&quot;&gt;months
      &lt;option value=&quot;y&quot;&gt;days of year
      &lt;option value=&quot;d&quot;&gt;days
      &lt;option value=&quot;w&quot;&gt;weekdays
      &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;/pre&gt;

&lt;input type=&quot;Submit&quot; name=&quot;&quot;&gt;&lt;input type=&quot;RESET&quot;&gt;
&lt;/form&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 specifying the units in which to count; for example yyyy requests a date difference in whole years.</p><ul>

<li>yyyy: Years</li>

<li>q: Quarters</li>

<li>m: Months</li>

<li>y: Days of year (same as d)</li>

<li>d: Days</li>

<li>w: Weekdays (same as ww)</li>

<li>ww: Weeks</li>

<li>h: Hours</li>

<li>n: Minutes</li>

<li>s: Seconds</li>
</ul>


  </td>
  </tr>
  </table>
</div>
<div id="DATE1">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">DATE1</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>
<div id="DATE2">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">DATE2</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>
