title: PHP: Work out duration between two times
body: <p>Ok, a really simple question but I am too thick to figure it out. I want to get the difference between two times. For example, "1:07" (1 minute and 7 seconds) and "3:01" (3 minutes and 1 second). It will only be ever minutes and seconds. I have been trying to make use of this:</p>
  
  <pre><code>function timeDiff($firstTime,$lastTime)
  {
  
  // convert to unix timestamps
  $firstTime=strtotime($firstTime);
  $lastTime=strtotime($lastTime);
  
  // perform subtraction to get the difference (in seconds) between times
  $timeDiff=$lastTime-$firstTime;
  
  // return the difference
  return $timeDiff;
  }
  </code></pre>
  
  <p>But I think I am running in the wrong direction?</p>
  
  <p>Thank you for any help. </p>
  
  <h2>EDIT</h2>
  
  <p>I tried this: echo timeDiff('1:07','2:30');</p>
  
  <p>I got this output "4980"</p>
  
  <p>What is the above? Is it seconds? I have no idea how to get it as "1:23" which is the difference.</p>
  
  <h2>EDIT 2</h2>
  
  <p>Thank you all, I learnt so much just from this one thread, esp. Paul's. It works very well and I like the defensiveness!</p>