Solved

Loop through months, into next year

Posted on 2009-04-01
5
1,006 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…

749 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