Page 1 of 1

Time, 10 Minutes Ago

Posted: Thu Mar 19, 2009 10:27 am
by SheDesigns
I'm writing a script to find active users. What's the easiest way to check within the last ten minutes.

Every action the user makes, is logged in the db under the "LastActive" colum. (ex - 2009-03-19 09:35:00)

If the current time is 2009-03-19 09:39:00, my example should show.
What is the easiest way to go about checking if they've been active in the past 10 minutes?

Re: Time, 10 Minutes Ago

Posted: Thu Mar 19, 2009 10:43 am
by William
http://dev.mysql.com/doc/refman/5.1/en/ ... tions.html

Code: Select all

 
SELECT something FROM tbl_name WHERE DATE_SUB(CURDATE(),INTERVAL 10 MINUTE) <= LastActive;
 
Is that what you're looking for?

Re: Time, 10 Minutes Ago

Posted: Thu Mar 19, 2009 11:02 am
by jayshields

Code: Select all

SELECT * FROM `users` WHERE `LastActive` > NOW() - INTERVAL 10 MINUTE

Re: Time, 10 Minutes Ago

Posted: Thu Mar 19, 2009 11:10 am
by William
jayshields wrote:

Code: Select all

SELECT * FROM `users` WHERE `LastActive` > NOW() - INTERVAL 10 MINUTE
Is there any performance gain with this syntax over the one I posted?

Edit: Agreed, it does read a lot better.

Re: Time, 10 Minutes Ago

Posted: Thu Mar 19, 2009 11:57 am
by jayshields
Doubt it. Mine is just easier to read.