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.
Definition and Usage. The CURDATE() function returns the current date. Note: The date is returned as "YYYY-MM-DD" (string) or as YYYYMMDD (numeric). Note: This function equals the CURRENT_DATE() function.
The NOW() function gives current datetime as a timestamp while CURDATE() gives only current date, not time.
In MySQL, use the DATE() function to retrieve the date from a datetime or timestamp value. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a timestamp/datetime column.
The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format.
Try CAST
ing 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With