title: Calculate elapsed time in php
body: <p>Hi All I'm trying to calculate elapsed time in php.  The problem is not in php, it's with my mathematical skills.  For instance:
  Time In:  11:35:20 (hh:mm:ss), now say the current time is: 12:00:45 (hh:mm:ss) then the time difference in my formula gives the output:  <strong>1:-34:25</strong>.  It should actually be:  25:25</p>
  
  <pre><code>$d1=getdate();
  $hournew=$d1['hours'];
  $minnew=$d1['minutes'];
  $secnew=$d1['seconds'];
  
  $hourin = $_SESSION['h'];
  $secin = $_SESSION['s'];
  $minin = $_SESSION['m'];
  
  $h1=$hournew-$hourin;
  $s1=$secnew-$secin;
  $m1=$minnew-$minin;
  
  if($s1&lt;0) {
      $s1+=60; }
  if($s1&gt;=(60-$secin)) {
      $m1--;  }
  if($m1&lt;0) {
      $m1++; }
  echo $h1 . ":" . $m1 . ":" . $s1;
  </code></pre>
  
  <p>Any help please?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Sorry I probably had to add that the page refreshes every second to display the new elapsed time so I have to use my method above.  My apologies for not explaining correctly.</p>