Strtotime not correct on when calculating relative time between user login time and now
<p>User login time is saved in Database(Mysql).I need the relative time betwwen login and now.</p>

<p>I used strtotime , but not getting correct .</p>

<p>First time when  login  gives strtotime as  '1322787648' , then
calculate strtotime now      '1322831782'  , then again I login in
this time it get             '1322788641'  .</p>

<p>Here Second login strtotime value is lesser than  strtotime('NOW') which IS calculated before second login.</p>

<p>I think calculating strtotime in afternoon get error but forenoon it works great.</p>

<pre><code>    foreach ($chapterArray as $dat) {

        //$dat['date_time'] coming date from Database

        $time = strtotime($dat['date_time']);
        $now = strtotime('now');

        if (floor(($now - $time) / 86400) != 0) {
            $time = floor(($now - $time) / 86400) . ' days ago';
        }
        elseif (floor(($now - $time) / 3600) != 0) {
            $time = floor(($now - $time) / 3600) . ' hours ago';
        }

        elseif (floor(($now - $time) / 60) != 0) {
            $time = floor(($now - $time) / 60) . ' minutes ago';
        }
        else {
            $time = 'a few seconds ago';
        }
    }
</code></pre>
