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:
http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000293.htm
LikeLike
Dont let Gus take the wind out of your sails. You go, date looper guy!!!
LikeLike
Are there any problems on ColdFusion MX 6.1 or not?
LikeLike
I almost laughed when I seen the code… shit, it actually works! Nice one. Guess we should all RTFM. :p
LikeLike
Even better is if you take advantage of the step parameter. For example:
#DateFormat(date,”MM/DD/YYYY”)#-#TimeFormat(date,”HH:MM:SS”)#
will loop you through a range of dates, in 36 hour increments.
LikeLike
2nd try:
#LsDateFormat(date,”MM/DD/YYYY”)#-#TimeFormat(date,”HH:MM:SS”)#
LikeLike