title: Strange behavior of PHP time math: Why is strtotime() returning negative numbers?
body: <p>I'm trying to do some very basic time math - basically, given inputs of time and distance, calculate the speed. I chose to use strtotime() to convert the time inputs into seconds - but I'm getting some bizarre results.</p>
  
  <p>For example, given this sample program:</p>
  
  <pre><code>&lt;?php
  $t1 = strtotime("3:15:00",0);
  $t2 = strtotime("1:00:00",0);
  $t3 = strtotime("2:00:00",0);
  $t4 = strtotime("9:00:00",0);
  
  echo $t1 . "\n";
  echo $t2 . "\n";
  echo $t3 . "\n";
  echo $t4 . "\n";
  ?&gt;
  </code></pre>
  
  <p>Why do I get these results?</p>
  
  <pre><code>$ php test.php 
  -56700
  -64800
  -61200
  -36000
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>Since no one said it explicitly, let me explain the bug in the above function. I had assumed that passing a time of zero to strtotime() would cause it to generate time stamps derived from midnight, 12/31/1969, UTC - which sounds odd, but would work for my purposes.</p>
  
  <p>What I hadn't counted on was that strtotime() takes time zones into account when converting strings, and my server is apparently 5 hours behind UTC. On top of that, because of the time zone shift, PHP then interprets the times as relative to <strong>the day before the epoch</strong> which means it is interpreting my times as occurring relative to December <strong>30th</strong>, 1969 instead of the 31st, resulting in negative numbers...</p>
  
  <p>It appears that Eugene is correct - if I want to calculate just the elapsed time, I can't use the built in time functions.</p>