Shadowing Posted March 2, 2012 Share Posted March 2, 2012 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>"; } Quote Link to comment https://forums.phpfreaks.com/topic/258127-comparing-mysql-time-in-php/ Share on other sites More sharing options...
requinix Posted March 2, 2012 Share Posted March 2, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/258127-comparing-mysql-time-in-php/#findComment-1323184 Share on other sites More sharing options...
Shadowing Posted March 2, 2012 Author Share Posted March 2, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258127-comparing-mysql-time-in-php/#findComment-1323192 Share on other sites More sharing options...
Shadowing Posted March 2, 2012 Author Share Posted March 2, 2012 Yah i just assumed NOW was gmt so i need to go look up on how to make it record the time stamp in 0 GMT then. I didnt think once to check the time of the time stamp cause I thought it was a format issue lol. where it couldnt read it Quote Link to comment https://forums.phpfreaks.com/topic/258127-comparing-mysql-time-in-php/#findComment-1323194 Share on other sites More sharing options...
Shadowing Posted March 2, 2012 Author Share Posted March 2, 2012 Well im confused lol. using NOW and using UTC_TIMESTAMP is giving me the same time, which is server time. and server time is -6. im wanting 0 so its the same as strtotime anyone know what im doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/258127-comparing-mysql-time-in-php/#findComment-1323218 Share on other sites More sharing options...
Shadowing Posted March 2, 2012 Author Share Posted March 2, 2012 Ahh figured out my issue. The page i was making edits on wasnt even part of the page i was testing it on if i had it wraped in a function i wouldnt of had this issue Quote Link to comment https://forums.phpfreaks.com/topic/258127-comparing-mysql-time-in-php/#findComment-1323263 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.