CFLOOP: LOOPING OVER A DATE OR TIME RANGE |
Description 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.
Syntax
    <cfloop
       from = "start_time"
       to = "end_time"
       index = "current_value"
       step = "increment">
    </cfloop>
See also cfabort, cfbreak, cfdirectory, cfexecute, cfexit, cfif, cflocation, cfrethrow, cfswitch, cfthrow, cftry; "cfloop and cfbreak" in Chapter 2, "Elements of CFML," in ColdFusion MX Developer's Guide
Example 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:
    <cfset startDate = Now()>
    <cfset endDate = Now() + 30>
    <cfloop from="#startDate#" to="#endDate#" index="i"
    step="#CreateTimeSpan(7,0,0,0)#">
      <cfoutput>#dateformat(i, "mm/dd/yyyy")#<br /></cfoutput>
    </cfloop>
The following example displays the time in 30-minute increments, starting from midnight and ending 23 hours, 59 minutes, and 59 seconds later:
    <cfset startTime = CreateTime(0,0,0)>
    <cfset endTime = CreateTime(23,59,59)>
    <cfloop from="#startTime#" to="#endTime#" index="i"
    step="#CreateTimeSpan(0,0,30,0)#">
     <cfoutput>#TimeFormat(i, "hh:mm tt")#<br /></cfoutput>
    </cfloop>

FROM |
| Required
The beginning of the date or time range.

TO |
| Required
The end of the date or time range.

INDEX |
| Required
Default value: "1 day" Index value. ColdFusion sets it to the from value and increments by the step value, until it equals the to value.

STEP |
| Optional
Step, expressed as a timespan, by which the index increments.