Jump to content

Trying to work with TIMEDIFF


HokieTracks

Recommended Posts

I am trying to find the difference between the current datetime and the datetime the user was last active. But for whatever reason the code isn't outputting anything but it doesn't have any errors either.

 

$lastactive = $row_userdata['lastactive'];
$now = date("Y-m-d H:i:s");

$activequery = "SELECT TIMEDIFF('$lastactive','$now') AS '$difference'";
mysql_query($activequery) or die(mysql_error());
echo $difference;

Link to comment
https://forums.phpfreaks.com/topic/162169-trying-to-work-with-timediff/
Share on other sites

Executing a second query just to calculate a difference using data from a database kind of defeats the point of using the mysql functions in a query. You should be using the TIMEDIFF() logic in your first SELECT query that is getting $row_userdata['lastactive'].

 

Also the mysql NOW() function does the same thing as your $now php code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.