Time, 10 Minutes Ago

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SheDesigns
Forum Commoner
Posts: 42
Joined: Tue Nov 18, 2008 9:51 am
Location: Buffalo, NY

Time, 10 Minutes Ago

Post 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?
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Re: Time, 10 Minutes Ago

Post 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?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Time, 10 Minutes Ago

Post by jayshields »

Code: Select all

SELECT * FROM `users` WHERE `LastActive` > NOW() - INTERVAL 10 MINUTE
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Re: Time, 10 Minutes Ago

Post 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.
Last edited by William on Thu Mar 19, 2009 12:50 pm, edited 1 time in total.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Time, 10 Minutes Ago

Post by jayshields »

Doubt it. Mine is just easier to read.
Post Reply