Joshua F Posted September 25, 2010 Share Posted September 25, 2010 I have a database with Users as a table. It has the normal stuff, id, username, password, and I have anther in it called lastactive. It is DATETIME, and I am wondering how I would make a sql query select the users in the database 'users' and see who has been active in the past 15 mins. What I am asking is how I could do this, and would it be better to use a different structure other then DATETIME. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2010 Share Posted September 25, 2010 Tested this locally, and it should produce the results you're after. SELECT `whatever` from `Users` WHERE ( TIMESTAMPDIFF(MINUTE, `lastactive`, NOW() ) < 15 ) Quote Link to comment Share on other sites More sharing options...
Joshua F Posted September 25, 2010 Author Share Posted September 25, 2010 So, with that, should I use DATETIME or something else, or does it matter? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2010 Share Posted September 25, 2010 That is made to work with the DATETIME field data type. I almost never use unix timestamps, especially in a database. Quote Link to comment Share on other sites More sharing options...
Joshua F Posted September 25, 2010 Author Share Posted September 25, 2010 Alright, thanks. Got it working. Quote Link to comment Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Share Posted September 25, 2010 Okay I did this, but mine is still bringing back no results. Quote Link to comment Share on other sites More sharing options...
lalnfl Posted September 25, 2010 Share Posted September 25, 2010 Nevermind. I just had to remove the '' around my database field name and now it works. Thanks for the help. Quote Link to comment 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.