Not yet rated

Problem

Need to loop from a start date until an end date by a specified time span.

Solution

We use the cfloop tag with both dates and set the step property to our specified time span (15 minutes). The code inside the loop will be executed for each interval between the start date and end date.

Detailed explanation

<!--- Set the start date to the current date and time --->
<cfset startDate = now()/>
 
<!--- Set the end date to two hours ahead of the current date and time --->
<cfset endDate = dateAdd("h", 2, startDate)/>
 
<!--- Loop over the time between start date and end date for each interval specified --->
<cfloop index="time" from="#startDate#" to="#endDate#" step="#createTimeSpan(0,0,15,0)#">
<!--- Display the time for each interval --->
<cfoutput><p>#timeFormat(time, "full")#</p></cfoutput>
</cfloop>

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes