Skip to main content
March 11, 2010
Question

Finding month and month start and end date from start and end date.

  • March 11, 2010
  • 1 reply
  • 284 views

i got start  date as 11/01/2009

End date as 10/31/2010

from start date and End date, i want to find how many months between.

what are start and end date of each month in between.

Is there any custom tag available?

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    March 11, 2010

    The dateDiff() function can tell you the number of months between the two dates.  Then you would use a loop to increment over each month and use the DaysInMonth() function to tell you the end date of each month.  The start date of the month is easy.. it is always the first!

    No custom tag.. but there is custom code.

    <cfset startdate = '11-01-2009' />
    <cfset endDate = '10-31-2010' />

    <cfset numberOfMonths = dateDiff( "m", startDate, endDate ) />

    <cfloop from="0" to="#numberOfMonths#" index="idx">
        <cfset loopDate = DateAdd( "m", idx, startDate )>
     
      <cfset beginningOfMonth = CreateDate( year(loopDate), month(loopDate), 1 )/>
      <cfset endingOfMonth = CreateDate( year(loopDate), month(loopDate), daysInMonth(loopDate) )/>

        <cfoutput>
          #dateFormat(beginningOfMonth)# to #dateFormat(endingOfMonth)#<br/>
      </cfoutput>

    </cfloop>