How to loop over a date range in ColdFusion

cfloop - loop over a date range

cfloopdate.cfm



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfloop tag example: how to loop over a date range in coldfusion</title>
</head>

<body>
<h2 style="color:Crimson">cfloop Tag Example: date range</h2>

<cfset LoopStartDate="5-Dec-2008">
<cfset LoopEndDate="12-Dec-2008">

<cfoutput>
 <b>LoopStartDate:</b> #LoopStartDate#<br />
 <b>LoopEndDate:</b> #LoopEndDate#<br />
</cfoutput>
<br /><br />

Loop start ...<br />

<cfloop from="#LoopStartDate#" to="#LoopEndDate#" index="i">
 <cfoutput>
     <b>Current Position:</b> #DateFormat(i)#<br />
    </cfoutput>
</cfloop>

<br /><br />
Loop start[step 2 days] ...<br />
<cfloop from="#LoopStartDate#" to="#LoopEndDate#" index="i" step="#CreateTimeSpan(2,0,0,0)#">
 <cfoutput>
     <b>Current Position:</b> #DateFormat(i)#<br />
    </cfoutput>
</cfloop>
</body>
</html>







More ColdFusion examples