Jump to content

Online in last 24 hour


thaidomizil

Recommended Posts

Hi, i'm trying to create some detailed statistics about customer activity, i have entries in my mysql db when the customer has been active for the last time and want to create some statistics about that, basically a "online last 24 hours" but from specific countries.

 

Now i've tried this:

 

	
$time = date('Y-m-d H:i:s');
$time24 = date("Y-m-d H:i:s", time()-((60*60)*24));
$query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND time BETWEEN '$time' AND '$time24' ";

 

to get the current date and select all customers that have been available from the current date minus 24 hours, what's my mistake here, as this doesn't seem to work!

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/251068-online-in-last-24-hour/
Share on other sites

The lower value needs to come first in a BETWEEN comparison, but this would be better handled in the query anyhow. PHP's DATE function is pretty slow.

 

time BETWEEN DATE_SUB( NOW(), INTERVAL 24 HOUR ) and NOW()

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.