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.
Syntax
<cfloop from = "start time" to = "end time" index = "current value" step = "increment"> </cfloop>
See also
cfabort, cfbreak, cfcontinue, cfdirectory, cfexecute, cfexit, cfif, cflocation, cfrethrow, cfswitch, cfthrow, cftry; cfloop
and cfbreak in the Developing ColdFusion Applications
Attributes
Attribute |
Req/Opt |
Default |
Description |
---|---|---|---|
fromDate |
Required |
|
The beginning of the date or time range. |
toDate |
Required |
|
The end of the date or time range. |
index |
Required |
|
Numeric index value. ColdFusion sets it to the numeric equivalent of the from value and increments by the numeric equivalent of the step value, until it equals the numeric equivalent of the to value. |
step |
Optional |
1 day |
Step, expressed as a timespan, by which the index increments. |
Example
<cfset fromDate = Now()> <cfset toDate = Now() + 30> <cfloop from="#fromDate#" to="#toDate#" index="i" step="#CreateTimeSpan(7,0,0,0)#"> <cfoutput>#dateformat(i, "mm/dd/yyyy")#<br /></cfoutput> </cfloop>
<cfset fromDate = Now()> <cfset toDate = Now() + 30> <cfloop from="#fromDate#" to="#toDate#" index="i" step="#CreateTimeSpan(7,0,0,0)#"> <cfset i = dateAdd("d", 0, i)><!--- converts number to date ---> <cfoutput>#i.dateTimeFormat("mm/dd/yyyy")#</cfoutput> </cfloop>
<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>
Output
12:00 AM
12:30 AM
01:00 AM
01:30 AM
..........
Adobe
Recevez de l’aide plus rapidement et plus facilement
Nouvel utilisateur ?