<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CFLOOP: LOOPING OVER A DATE OR TIME RANGE</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">CFLOOP: LOOPING OVER A DATE OR TIME RANGE</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>
Loops over the date or time range specified by the from and to attributes. By default, the step is 1 day, but you can change the step by creating a timespan. The cfloop tag loops over tags that cannot be used within a cfoutput tag. 
</p>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="syntax"><span class="title">Syntax</span><pre>&lt;cfloop 
   from = &quot;start_time&quot;
   to = &quot;end_time&quot;
   index = &quot;current_value&quot;
   step = &quot;increment&quot;&gt;
&lt;/cfloop&gt;
</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>
cfabort, cfbreak, cfdirectory, cfexecute, cfexit, cfif, cflocation, cfrethrow, cfswitch, cfthrow, cftry; "cfloop and cfbreak" in Chapter&#160;2, "Elements of CFML," in ColdFusion MX Developer's Guide
</p>

<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">Example</span>
<p>
The following example loops from today's date to today's date plus 30 days, stepping by 7 days at a time and displaying the date:
</p>
<pre>&lt;cfset startDate = Now()&gt; 
&lt;cfset endDate = Now() + 30&gt;
&lt;cfloop from=&quot;#startDate#&quot; to=&quot;#endDate#&quot; index=&quot;i&quot; 
step=&quot;#CreateTimeSpan(7,0,0,0)#&quot;&gt;
  &lt;cfoutput&gt;#dateformat(i, &quot;mm/dd/yyyy&quot;)#&lt;br /&gt;&lt;/cfoutput&gt;
&lt;/cfloop&gt;
</pre>
<p>
The following example displays the time in 30-minute increments, starting from midnight and ending 23 hours, 59 minutes, and 59 seconds later:
</p>
<pre>&lt;cfset startTime = CreateTime(0,0,0)&gt; 
&lt;cfset endTime = CreateTime(23,59,59)&gt; 
&lt;cfloop from=&quot;#startTime#&quot; to=&quot;#endTime#&quot; index=&quot;i&quot; 
step=&quot;#CreateTimeSpan(0,0,30,0)#&quot;&gt; 
 &lt;cfoutput&gt;#TimeFormat(i, &quot;hh:mm tt&quot;)#&lt;br /&gt;&lt;/cfoutput&gt;
&lt;/cfloop&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="FROM">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">FROM</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>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>The beginning of the date or time range.</p>

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

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>The end of the date or time range. </p>

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

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">

<strong>Default value:</strong> "1 day"


<p>Index value. ColdFusion sets it to the from value and increments by the step value, until it equals the to value.</p>

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

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Optional</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>Step, expressed as a timespan, by which the index increments.</p>

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

  </body>
</html>
