Doesn't work, since DateDiff() only seems to count the number of full months between dates. DateDiff("11/17/2003", "2/12/2005"), for instance, returns 2.
----- Original Message ----- From: "Jeff Garza" <[EMAIL PROTECTED]> To: "CF-Talk" <cf-talk@houseoffusion.com> Sent: Monday, January 10, 2005 3:25 PM Subject: Re: Suggestion for looping over months within a time period > This works for me... > > <CFPARAM name="startDate" default = "11/17/2003"> > <CFPARAM name="endDate" default="2/19/2004"> > <!--- Get the number of months between the two dates... ---> > <CFSET numMonths = DateDiff("m", startDate, endDate)> > <CFOUTPUT>Difference in Months: #numMonths#<BR><BR></CFOUTPUT> > > <!--- Loop, obviously and increment the base date by one month ---> > <CFLOOP from="0" to="#numMonths#" index="i"> > <CFSET baseDate = Month(DateAdd("m", i, startDate)) & "/1/" & > Year(DateAdd("m", i, startDate))> > <CFSET baseEndDate = Month(baseDate) & "/" & Daysinmonth(baseDate) & > "/" > & Year(baseDate)> > <CFOUTPUT>StartDate = #baseDAte# ||| EndDate = > #baseEndDate#<BR></CFOUTPUT> > </CFLOOP> > > Hope this helps... > > Jeff Garza > > ----- Original Message ----- > From: "Jim McAtee" <[EMAIL PROTECTED]> > To: "CF-Talk" <cf-talk@houseoffusion.com> > Sent: Monday, January 10, 2005 3:02 PM > Subject: Suggestion for looping over months within a time period > > >> What is a good way to loop over the months within a time period? For >> example, given a starting date of 11/17/2003 and an end date of >> 2/19/2003, >> I'd need to loop through Nov03, Dec03, Jan04, Feb04. Within the loop >> I'll >> be doing queries with a where clause like: >> >> WHERE somedate BETWEEN #month#/1/#year# >> AND #month#/#DaysInMonth("#month#/1/#year#")#/#year# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:189861 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54