Time Function not correctly calculating
<p>My time calculations are not correct I have a time.php that is called in my profile.php to calculate the last time a message was sent etc </p>

<p>I have the following line that calls the function time_passed for the row time</p>

<pre><code>echo "time_passed"($row['time']);
</code></pre>

<p>Here is the CODE for calculating time</p>

<pre><code>   &lt;?php

  // DISPLAYS COMMENT POST TIME AS "1 year, 1 week ago" or "5 minutes, 7    seconds ago", etc...
 function time_passed($timestamp){
//type cast, current time, difference in timestamps
$timestamp      = (int) $timestamp;
$current_time   = time();
$diff           = $current_time - $timestamp;

//intervals in seconds
$intervals      = array (
    'year' =&gt; 31556926, 'month' =&gt; 2629744, 'week' =&gt; 604800, 'day' =&gt; 86400, 'hour' =&gt; 3600, 'minute'=&gt; 60
);

//now we just find the difference
if ($diff == 0)
{
    return 'just now';
}    

if ($diff &lt; 60)
{
    return $diff == 1 ? $diff . ' second ago' : $diff . ' seconds ago';
}        

if ($diff &gt;= 60 &amp;&amp; $diff &lt; $intervals['hour'])
{
    $diff = floor($diff/$intervals['minute']);
    return $diff == 1 ? $diff . ' minute ago' : $diff . ' minutes ago';
}        

if ($diff &gt;= $intervals['hour'] &amp;&amp; $diff &lt; $intervals['day'])
{
    $diff = floor($diff/$intervals['hour']);
    return $diff == 1 ? $diff . ' hour ago' : $diff . ' hours ago';
}    

if ($diff &gt;= $intervals['day'] &amp;&amp; $diff &lt; $intervals['week'])
{
    $diff = floor($diff/$intervals['day']);
    return $diff == 1 ? $diff . ' day ago' : $diff . ' days ago';
}    

if ($diff &gt;= $intervals['week'] &amp;&amp; $diff &lt; $intervals['month'])
{
    $diff = floor($diff/$intervals['week']);
    return $diff == 1 ? $diff . ' week ago' : $diff . ' weeks ago';
}    

if ($diff &gt;= $intervals['month'] &amp;&amp; $diff &lt; $intervals['year'])
{
    $diff = floor($diff/$intervals['month']);
    return $diff == 1 ? $diff . ' month ago' : $diff . ' months ago';
}    

if ($diff &gt;= $intervals['year'])
{
    $diff = floor($diff/$intervals['year']);
    return $diff == 1 ? $diff . ' year ago' : $diff . ' years ago';
}
}

?&gt;
</code></pre>

<p>The result is as follows </p>

<p><a href="https://i.stack.imgur.com/ln4Wk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ln4Wk.png" alt="enter image description here"></a></p>

<p>My table is </p>

<p><a href="https://i.stack.imgur.com/FNwkl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FNwkl.png" alt="enter image description here"></a></p>

<p>The time is inserted in the following format </p>

<p><a href="https://i.stack.imgur.com/bGD0z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bGD0z.png" alt="enter image description here"></a></p>

<p>The time gets inserted automatically when a query is ran,   then I show back the results in a table above but its says 46 years ago , What is possible causing this ? Thanks</p>