Solved

Loop through months, into next year

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

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…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

739 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