yudayyy yudayyy - 2 months ago 10
SQL Question

SQL SELECT * FROM datetime = CURDATE() return an empty result set

Can anyone tell me where's my mistake? By using that query, it should return some rows where the data have datetime = '2012-10-12' right? Here is my reference

My datetime column = 'YYYY-MM-DD HH:MM:SS', data type = datetime.

I am using XAMPP v1.8.0, MySQL v5.5.25a.

Answer

Try CASTing datetime to date by using DATE()

SELECT * 
FROM tableName
WHERE DATE(`datetime`) = DATE(CURDATE())

YYYY-MM-DD HH:MM:SS is not equal to YYYY-MM-DD

2012-01-01 12:12:12 is not equal to 2012-01-01 00:00:00