I am trying to loop over motnhs like.
<cfloop index="i" from="05-2012" to="12-2012" step="#createTimeSpan(31, 0, 0, 0)#">
#LSDateFormat(i, "MMM")#
</cfloop>
but it displays months only till Nov 2012. in order to display the Dec 2012 I have to put
#LSDateFormat(i, "MMM")#
again after the loop. any suggestion?
I guess this is because “12-2012” is “01-12-2012” and you are using 31 days step (which is not the same as one month). So last iteration is looking for 04-12-2012 while your “to” is 01-12-2012. You can easily see this problem like this:
Simple solution would be this:
Plus it looks a bit more readable for me.
Please note that in case of longer period problem may appear again. Most reliable solution would be to make the span equal to 1 month, say use something like this:
See, it is always 1st day of the month.