tags:

views:

38

answers:

5

In my table dates are stored in the format "2010-08-26 09:00:00" so yyyy-mm-dd. I'd like to select all fields that have a date field that is "today", so between 2010-08-26 00:00:01 and 2010-08-26 23:59:59.

Just using larger and smaller than operators does not work, does MySQL have some built in date comparison functions that can do this?

EDIT: I should have mentioned dates are stored as datetime fields

A: 

Using the DATE() function you should be able to construct a value for comparison:

DATE(2010-08-26 12:13:24)

will return just the date section for you ie. 2010-08-26.

simnom
A: 

I'd suggest [...] WHERE DATEDIFF(CURDATE(),date_field) = 0 [...]

pharalia
A: 

Just a recommendation for the future: storing a date in a varchar column is almost always a very bad idea.

a_horse_with_no_name
+1  A: 
... WHERE DATE(field)=CURDATE()

or

... WHERE DATE(field)=CURRENT_DATE

or

... WHERE DATE(field)=CURRENT_DATE()

Pick one!

Vili
Just for completness: I usually use DATE(field)=DATE(NOW()) which might be less performant but easier to remember.
dbemerlin