Jump to content

User count registered today


thaidomizil

Recommended Posts

Hello,

 

i'm trying to get the number of users that registered today and the number of users that registered yersterday (seperate), i've got this field in mysql: 'registertime' which stores data in this format 2011-11-14 14:53:49 also i have the field 'time' in the same format that updates everytime the user logs in.

 

Now previously i wanted to find out users online in last 24 hours, the code i used for that is this:

 

$query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND time BETWEEN DATE_SUB( NOW(), INTERVAL 24 HOUR ) and NOW() ";
$queryerg = mysql_query($query) OR die(mysql_error());
while($row = mysql_fetch_array($queryerg)){
  $customers_on_de_24 = $row[0];
} 

 

How could i edit that to select the count just by date and ignore the time (hours minutes seconds) ?

Link to comment
Share on other sites

Now i've tried this:

 

$query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND DATE('registertime') = DATE(NOW())";
$queryerg = mysql_query($query) OR die(mysql_error());
while($row = mysql_fetch_array($queryerg)){
  $registrationstoday = $row[0];
} 

 

But for some reason it's showing me 0 ? What am i doing wrong ?

 

Edit:

 

removed the ' ' .. it works now!

 

Now how can i subtract one day from this DATE(NOW())"; ? So it's showing me the result for yesterday

Link to comment
Share on other sites

<?php
//today
$query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND DATE('registertime') = CURDATE()";
$queryerg = mysql_query($query) OR die(mysql_error());
while($row = mysql_fetch_array($queryerg)){
  $registrationstoday = $row[0];
}
//yesterday
$query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND DATE('registertime') = DATE_SUB(CURDATE(),INTERVAL 1 DAY)";
$queryerg = mysql_query($query) OR die(mysql_error());
while($row = mysql_fetch_array($queryerg)){
  $registrationstoday = $row[0];
} 

 

MySQL Date Functions

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.