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?
Time, 10 Minutes Ago
Moderator: General Moderators
- SheDesigns
- Forum Commoner
- Posts: 42
- Joined: Tue Nov 18, 2008 9:51 am
- Location: Buffalo, NY
Re: Time, 10 Minutes Ago
http://dev.mysql.com/doc/refman/5.1/en/ ... tions.html
Is that what you're looking for?
Code: Select all
SELECT something FROM tbl_name WHERE DATE_SUB(CURDATE(),INTERVAL 10 MINUTE) <= LastActive;
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Time, 10 Minutes Ago
Code: Select all
SELECT * FROM `users` WHERE `LastActive` > NOW() - INTERVAL 10 MINUTERe: Time, 10 Minutes Ago
Is there any performance gain with this syntax over the one I posted?jayshields wrote:Code: Select all
SELECT * FROM `users` WHERE `LastActive` > NOW() - INTERVAL 10 MINUTE
Edit: Agreed, it does read a lot better.
Last edited by William on Thu Mar 19, 2009 12:50 pm, edited 1 time in total.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Time, 10 Minutes Ago
Doubt it. Mine is just easier to read.