Timothée HENRY
Timothée HENRY

Reputation: 14604

SQL query to get records from same day

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().

Upvotes: 5

Views: 10464

Answers (1)

Kieren Johnstone
Kieren Johnstone

Reputation: 42003

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()

Upvotes: 11

Related Questions