title: php replacing old code with DateTime class
body: <p>I have a function that creates time intervals between two time marks. The function works but I'm struggling to upgrade from <code>strtotime()</code> and use the <code>DateTime</code> class.</p>
  
  <p>Below is a patch of code I wrote without getting errors</p>
  
  <pre><code>$timestart = new DateTime("14:00:00");
  $timestop = new DateTime("20:00:00");
  $date_diff = $timestop-&gt;diff($timestart);
  $time_diff = $date_diff-&gt;format('%H');
  </code></pre>
  
  <p>Next is the entire code untouched. I get <code>DateInterval could not be converted to int</code> erros using the code above. Please kindly advise how to correctly implement the class.</p>
  
  <p>Live example: <a href="http://codepad.org/jSFUxAnp" rel="nofollow">http://codepad.org/jSFUxAnp</a></p>
  
  <pre><code>function timemarks() 
      {       
  
          //times are actually retrieved from db
          $timestart = strtotime("14:00:00");
          $timestop = strtotime("20:00:00");
  
          $time_diff = $timestop - $timestart; //time difference
  
          //if time difference equals negative value, it means that $timestop ends second day 
          if ($time_diff &lt;= 0) 
          {
              $timestop = strtotime( '+1 day' , strtotime( $row-&gt;timestop ) ); //add 1 day and change the timetsamp
              $time_diff = $timestop - $timestart;
          }
  
          //create interval
          $split = 3;
          $interval = $time_diff/$split;
  
          //get all timemarks
          $half_interval = $interval / 2;
          $mid = $timestart + $half_interval;     
          for ( $i = 1; $i &lt; $split; $i ++) {
              //round intervals   
              $round_mid = round($mid / (15 * 60)) * (15 * 60);
              $result .= date('H:i:s', $round_mid) . ", ";
              $mid += $interval;
          }       
          $round_mid = round($mid / (15 * 60)) * (15 * 60);
          $result .= date('H:i:s', $round_mid);
  
          return $result;
      } 
  </code></pre>
  
  <p>outputs <code>15:00:00, 17:00:00, 19:00:00</code></p>