Solved

Loop through months, into next year

Posted on 2009-04-01
5
991 Views
Last Modified: 2012-05-06
I simply want to loop through months, 6 months out from last month.  

Something like this could be modified to work, but the problem is, I want to be able to overlap years.  So if it is Oct 09, I need to display the next 6 months... which runs into 2010... but the loop doesn't start over at 1 again.

<cfloop from="1" to="12" index="month">

#monthasstring(month)#<br />

</cfloop>

0
Comment
Question by:MFredin
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Jones911
ID: 24045329
How about this:

<cfset nowTime = now() />
<cfloop from="1" to="12" index="month">
   <cfoutput>#monthasstring(datePart("m",dateAdd("m",month,nowTime)))#</cfoutput>
</cfloop>
0
 

Author Comment

by:MFredin
ID: 24045351
Perfect! And how would I display the year with each month?
0
 
LVL 19

Expert Comment

by:Jones911
ID: 24045421
<cfset nowTime = now() />
<cfloop from="1" to="12" index="month">

  <cfoutput>Year: #datePart("yyyy",dateAdd("m",month,nowTime))# Month: #monthasstring(datePart("m",dateAdd("m",month,nowTime)))#<br /></cfoutput>
</cfloop>

Try this.
0
 
LVL 19

Accepted Solution

by:
Jones911 earned 250 total points
ID: 24045423
It line wrapped.
<cfset nowTime = now() />

<cfloop from="1" to="12" index="month">
 

<cfoutput>Year: #datePart("yyyy",dateAdd("m",month,nowTime))# Month: #monthasstring(datePart("m",dateAdd("m",month,nowTime)))#<br /></cfoutput>

</cfloop>

Open in new window

0
 

Author Comment

by:MFredin
ID: 24045489
Thank you! Works great!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now