This was one of those things that I did today expecting it not to work. The problem was that I had a set of dates I needed to iterate over (from a start date to today). I thought to myself, Self, wouldnt it be nice if I could simply loop from the start date to today somehow?
And so, I decided to give it a shot and see what happened. This is the code I tried:
<cfloop from="#Example.getStartDate()#" index="date" to="#now()#"> <cfoutput> #LsDateFormat(date)# </cfoutput> </cfloop>
Much to my amazement it worked. The loop started at the start date (in this case June 15th) and looped up today, one day at a time!
Comments on: "Looping over dates in ColdFusion" (6)
It’s all in the docs:
Dont let Gus take the wind out of your sails. You go, date looper guy!!!
Are there any problems on ColdFusion MX 6.1 or not?
I almost laughed when I seen the code… shit, it actually works! Nice one. Guess we should all RTFM. :p
Even better is if you take advantage of the step parameter. For example:
will loop you through a range of dates, in 36 hour increments.