problems with relative time function in php
<p>I have used many functions for relative time in php but that give different results...help me </p>

<p>My functions :</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"; } 
else    {return "Just Now"; }

}
function plural($num) {
if ($num != 1)
    return "s";
 }

   function getRelativeTime($date) {
$diff = time() - strtotime($date);
if ($diff&lt;60)
    return $diff . " second" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff&lt;60)
    return $diff . " minute" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff&lt;24)
    return $diff . " hour" . plural($diff) . " ago";
$diff = round($diff/24);
if ($diff&lt;7)
    return $diff . " day" . plural($diff) . " ago";
$diff = round($diff/7);
if ($diff&lt;4)
    return $diff . " week" . plural($diff) . " ago";
return "on " . date("F j, Y", strtotime($date));
 }


 echo pretty_relative_time('2012-08-06 8:04:15') ;echo "&lt;br/&gt;";
 echo getRelativeTime('2012-08-06 8:04:15');
 ?&gt; 
</code></pre>

<p>OutPut :</p>

<p>Just Now   // for first function</p>

<p>-15747 seconds ago // for second function</p>

<p>any settings in db ?.....i have used DATETIME for date...</p>
