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

有帮助吗?

解决方案

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())';
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top