Who's online in last 10 minutes? (dang dates - PHP/MySQL)

holdeN

Limp Gawd
Joined
Mar 15, 2002
Messages
258
This is killing me. I've read over the Date part of the PHP Manual a thousand times and am not having much luck :p

I have a Members table in MySQL. One piece of information I pull is $last_activity. $last_activity contains the date/time in the format that mysql uses with the now() (i.e. 2005-04-06 09:23:10). And that's the last time the user was on the site.

Now I want to find out if this user was online in the last 10 minutes. So I'm guessing I get the date/time of now and the dat/time of 10 minutes ago and see if $last_activity is in between those two variables? Right?

So, I'm having problems figuring out how to get the variable for 10 minutes ago and even now in the correct format to compare $last_activity to. Any help is grealty appreciated!!!!
 
if you're looking for a list of people who've been online in the last 10 minutes, make mysql do all the work, not php
Code:
SELECT * FROM tbl WHERE DATE_SUB(NOW(), INTERVAL 10 MINUTE) <= datetime;
i think that should work
be sure to look over the mysql date/time functions
http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

ninja edit:
i had " && datetime <= NOW()" but that's really not necessary since, presumably, nobody is going to be active at some point in the future
 
Back
Top