Jump to content

Query based on todays date


honkmaster

Recommended Posts

Hi look for some help with querying based on todays date. I'm trying to count all the entries in the database based on username, status, date. The date bit is where I' stuck (see screen shot of database)

 

Based on data in database I should get a count of 3 but get nothing??

 

The result I get is 0 and should be 3 based on date

 

Any help would be a great help Cheers Chris


//date bit
$d=strtotime("today");
$wholedate2 = date("Y-m-d", $d);

//query
$query_rsUser = "SELECT COUNT(*) FROM quotes WHERE quotes.quote_user = 'username' AND quotes.quote_complete = '$date2' AND quotes.quote_status = 'Complete'";
Link to comment
https://forums.phpfreaks.com/topic/296699-query-based-on-todays-date/
Share on other sites

First off you are using $wholedate2 and $date2, pick one.

 

If you used datetime your way could have worked, since is a timestamp needs like this.

 

This has to do calculations on everything and is a waste.

$query_rsUser = "SELECT COUNT(*) FROM quotes WHERE quotes.quote_user = 'username' AND DATE(quotes.quote_complete) = CURDATE() AND quotes.quote_status = 'Complete'";

Instead something like:

$query_rsUser = "SELECT COUNT(*) FROM quotes WHERE quotes.quote_user = 'username' AND quotes.quote_complete BETWEEN '".$wholedate2." 00:00:00' AND '".$wholedate2". 23:59:59' AND quotes.quote_status = 'Complete'";

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.