title: datetime: split a month 10-day periods
body: <p>I send a earlier date and it returns me the periods between the earlier date and today cut by tens of days.</p>
  
  <blockquote>
    <p>Example with 14/01/2016</p>
  </blockquote>
  
  <p><strong>I need the result to be exactly as below:</strong></p>
  
  <ul>
  <li>11 Jan 2016 to 20 Jan 2016</li>
  <li>21 Jan 2016 to 31 Jan 2016</li>
  <li>01 Feb 2016 to 10 Feb 2016</li>
  <li>11 Feb 2016 to 20 Feb 2016</li>
  <li>21 Feb 2016 to 29 Feb 2016</li>
  <li>01 Mar 2016 to 10 Mar 2016</li>
  <li>11 Mar 2016 to 20 Mar 2016</li>
  <li>21 Mar 2016 to 31 Mar 2016</li>
  <li>01 Apr 2016 to 10 Apr 2016</li>
  <li>11 Apr 2016 to 20 Apr 2016</li>
  </ul>
  
  <p><strong>Here my code:</strong></p>
  
  <pre><code>function date_interval($startTime = false){
  
      if( ! $startTime){
  
          return array();
      } else {
  
      if(date('d',$startTime) &lt; 10){
          $actual = mktime(0, 0, 0, date('m',$startTime), 1, date('Y',$startTime));
      } elseif(date('d',$startTime) &lt; 20){
          $actual = mktime(0, 0, 0, date('m',$startTime), 10, date('Y',$startTime));
      } else {
          $actual = mktime(0, 0, 0, date('m',$startTime), 20, date('Y',$startTime));
      }
  
      if(date('d',time()) &lt; 10) {
          $target = mktime(0, 0, 0, date('m',time()), 10, date('Y',time()));
      } elseif(date('d',time()) &lt; 20) {
          $target = mktime(0, 0, 0, date('m',time()), 20, date('Y',time()));
      } else {
          $target = mktime(0, 0, 0, date('m',time())+1, 1, date('Y',time()));
      }
  
  
      $current = $actual;
      $last = $actual;
  
      while($current &lt; $target) {
  
          if(date('d',$current) &lt; 10){
              $current = mktime(0, 0, 0, date('m',$current), 10, date('Y',$current));
          } elseif(date('d',$current) &lt; 20){
              $current = mktime(0, 0, 0, date('m',$current), 20, date('Y',$current)); 
          } else {
              $current = mktime(0, 0, 0, date('m',$current)+1, 1, date('Y',$current));
          } 
          $dateTime[date("Y-m-d", $last) .'~'. date("Y-m-d", $current)] = date('d M Y',$last) . ' - ' . date('d M Y',$current));
          $last = $current;
          }
      }
      return $dateTime;
  }
  </code></pre>