Jump to content

Recommended Posts

Hey guys, im having a slight issue with comparing mysql time stamp.

I'm using the timestamp in mysql to show how many people are online with in 5 minutes.

$sql = mysql_query("SELECT name,id FROM users WHERE DATE_SUB(NOW(),
INTERVAL 5 MINUTE) <= last_active ORDER BY id ASC"); 

But I want to grab last_active from the data base and compare it like below.  I dont know if strtotime just doesnt compare with mysql time stamp or what?

 

if($last_active > strtotime('-5 minutes')) {

	echo "<td>Online</td>";
}else{
	echo "<td>Offline</td>";

} 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/258127-comparing-mysql-time-in-php/
Share on other sites

I dont know if strtotime just doesnt compare with mysql time stamp or what?

Think. Why would it?

If your web and database servers are in different timezones then dates and times will differ between them. Pick one place to do dates. Personally I prefer using PHP for it, but that's just my choice.

 

Now, what you're saying is contradictory. Do you want only the people online within the last five minutes, or do you want all the people and to display which ones are online?

thanks for the responce requinix

 

Im recording the Time stamp with NOW. I figure that is 0 GMT. Thought strtotime was the same.

UPDATE users SET last_active = NOW()

 

but yah im displaying everyone and showing which ones are online and which ones are offline.

 

the query in my question is already is grabing the people online from with in the last 5 minutes. Sorry for the confusion on what im trying to do. :)

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.