ColdFusion 9.0 Resources |
cfloop: looping over a date or time rangeDescriptionLoops 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 alsocfabort, cfbreak, cfcontinue, cfdirectory, cfexecute, cfexit, cfif, cflocation, cfrethrow, cfswitch, cfthrow, cftry; cfloop and cfbreak in the Developing ColdFusion Applications Attributes
ExampleThe 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> |