Jump to content

Comparing mysql time in php


Shadowing

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

  Quote

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. :)

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.