title: PHP converting DATETIME into time ago function, seconds, minutes, hours, days etc
body: <p>I am using the following php function to convert my standard DATETIME result into a facebook style time ago, which shows the number of seconds, minutes and hours, days etc of that date. </p>
  
  <p>Here's my php function:</p>
  
  <pre><code>&lt;?php
  function pretty_relative_time($time) {
   if ($time !== intval($time)) { $time = strtotime($time); }
   $d = time() - $time;
   if ($time &lt; strtotime(date('Y-m-d 00:00:00')) - 60*60*24*3) {
   $format = 'F j';
   if (date('Y') !== date('Y', $time)) {
  $format .= ", Y";
   }
   return date($format, $time);
   }
   if ($d &gt;= 60*60*24) {
   $day = 'Yesterday';
   if (date('l', time() - 60*60*24) !== date('l', $time)) { $day = date('l', $time); }
   return $day . " at " . date('g:ia', $time);
   }
   if ($d &gt;= 60*60*2) { return intval($d / (60*60)) . " hours ago"; }
   if ($d &gt;= 60*60) { return "about an hour ago"; }
   if ($d &gt;= 60*2) { return intval($d / 60) . " minutes ago"; }
   if ($d &gt;= 60) { return "about a minute ago"; }
   if ($d &gt;= 2) { return intval($d) . " seconds ago"; }
   return "a few seconds ago";
  }
  ?&gt;
  </code></pre>
  
  <p>And here's where I call the function:</p>
  
  <pre><code>echo pretty_relative_time($row1['date']);
  </code></pre>
  
  <p>the problem I'm having is the script almost works 100%, however if something is dated within an hour it only ever shows 'about an hour ago' even if I've posted something within a couple of minutes or seconds. Can someone please show me what I am doing wrong? My date is stored as a DATETIME stamp</p>