yudayyy yudayyy - 1 year ago 93
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 Source

Try CASTing datetime to date by using DATE()

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