Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.