title: How to calculate the time consumed from start time to end time in php
body: <p>I want to get the perfect time consumed or the total time from start time to end time:<br /> My code:</p>
  
  <pre><code>   $start_time =  $this-&gt;input-&gt;post('start_time');
     $end_time =  $this-&gt;input-&gt;post('end_time');
  
  
     $t1  = strtotime($start_time);
     $t2 = strtotime($end_time);
     $differenceInSeconds = $t2 - $t1;
     $differenceInHours = $differenceInSeconds / 3600;
  
     if($differenceInHours&lt;0) {
       $differenceInHours += 24; 
      }
  </code></pre>
  
  <p>In the code above if <code>$start_time</code> = <code>11:00:00 PM</code> and <code>$end_date =11:30:00</code> it gives me the output of <code>0.5</code> instead of <code>30minutes</code>. Is there any appropriate way to do it like that? <br /> 
  So if the:</p>
  
  <pre><code>  $start_time  = '01:00:00 PM';
    $end_time = '01:25:00 PM';
  
    $total = '25:00'; // 25 minutes
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>  $start_time  = '11:00:00 PM';
    $end_time = '11:00:25 PM';
  
    $total = '00:00:25'; // 25seconds
  </code></pre>
  
  <p>Regards!</p>