title: How can I divide a date range by number of months?
body: <p>My dilemma is that if I request more than 6 months or so ( I do not know the approximate number ) from my webservices ( which gets called via JS ), I get nothing back. In other words, I have to limit it to 6 months.</p>
  
  <p>So let's consider this scenario:</p>
  
  <pre><code>$a = strtotime('June 3, 2011'); 
  $b = strtotime('June 3, 2012');
  </code></pre>
  
  <p>I need to split this up by 6 months in order to make 2 distinct web servicerequests so that each call requests 6 months.</p>
  
  <p>So with <code>$a</code> and <code>$b</code>, I need to split these up into as many date ranges as possible when taking the amount of months total divided by 6.</p>
  
  <p>The first date range I need is from June 1, 2011 to November 31, 2011. The second date range I need is from December 1, 2011 to July 1, 2012.</p>
  
  <p>The idea I had in mind was finding the number of months, then if it was greater than the limit variable <code>6</code>, do a loop and increment the initial date by 6 months per loop.</p>
  
  <p>Pseudo-code ( I actually initially wrote it in JS but figured it'd be easier to do in PHP because I wouldn't have to deal with multiple asynchronous request behaviour ):</p>
  
  <pre><code>   var numMonths = monthDiff ( a, b ), ret = [], limit = 6, loopLimit = Math.ceil( numMonths / limit ), ranges = [];
  
      if ( numMonths &gt; limit ) {
  
          for ( var i = 0; i&lt;loopLimit; i++ ) {
              var start = new Date(b);
              var end = new Date ( b.setMonth( b.getMonth() + limit ) );
              ranges.push( start, end );
          }
      }
  </code></pre>
  
  <p>Does anyone know of a succinct way of doing this? Can anyone spot any programmatic flaws in this?</p>