I wish to find all records of the current day.
I have a field Date
of type DATE.
If I use
WHERE `Date` = '2011-04-07'
it works
but if I use:
WHERE `Date`='CURDATE()'
or
WHERE `Date`='NOW()'
it does not return any results (when there actually are some).
How do I get the current date in the right format to use it in my SQL query?
I am using MySQL And the date was originally entered in the database using NOW().
Use
WHERE `Date`=CURDATE()
The quotes (') are used to wrap up a string (text).
Edit: I can see now that you say the value was stored with NOW()
: it probably includes a time element too. Will update answer imminently..
This will compare the date part of the Date field to today's date:
WHERE DATE(`Date`)=CURDATE()
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