How to calulate the difference between a MySQL timestamp and the current time in PHP

I'm trying to calculate the difference between a timestamp retrieved from a MySQL database and the current time.

Appreciate the help.

This question and answers originated from www.stackoverflow.com
Question by (4/15/2011 11:53:15 AM)

Answer

As mentioned by @RemoteSojourner, I got the current time in a UNIX timestamp format (which returns time in seconds), I got the timestamp from the DB (using an ORM) and converted that to a UNIX timstamp too and then subtracted the two timestamps.

            $current_time = strtotime("now");
            $last_access_time = strtotime($this->last_access);
            $inactivity_duration = $current_time - $last_access_time;
Answer by

Find More Answers
Related Topics  php  mysql  zend-framework  datetime  timestamp
Related Questions