Solved

Loop through months, into next year

Posted on 2009-04-01
5
1,019 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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