Solved

Loop through months, into next year

Posted on 2009-04-01
5
992 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

12 Experts available now in Live!

Get 1:1 Help Now