Question

I have a database that contains a column with type - Date. I also have a query with the date inputted as static which works fine but I would like to use todays date in the query. any recommendations?

Query :

 $q = 'SELECT count(ID) as count FROM ORDER WHERE 
ASSIGN_TO ='.$db->qstr($person).' AND OPEN_DATE ='.$db->qstr('2014-05-14');

This currently displays count of items after 2014-05-14

Was it helpful?

Solution

You could use the NOW() function that returns the current date. To avoid skewed answered by hours/minutes/seconds, you can use date to extract the date part:

$q = 'SELECT count(ID) as count FROM ORDER WHERE 
ASSIGN_TO ='.$db->qstr($person).' AND DATE(OPEN_DATE) = DATE(NOW())';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top