Q:

SQL Query not getting executing - returns empty set

I have a database table with date field whose data type is also date and i want to fetch those recods which lie betwnn two dates.
My query is :
SELECT * FROM wp_races_entry  WHERE date_in >=2012-02-08 && date_in<=2012-02-27

i also tried 
SELECT * FROM wp_races_entry WHERE date_in  BETWEEN 2012-02-08 AND 2012-02-27

i have records in table with date 2012-02-14 but still it return empty value.
Please help me guiding what i am missing exactly.

A:

You need quotes round your dates:
SELECT * FROM wp_races_entry WHERE date_in BETWEEN '2012-02-08' AND '2012-02-27'

Without the quotes your dates are treated as arithmetic expressions: 2012-02-08 = 2002.
The query you posted is equivalent to this:
SELECT * FROM wp_races_entry WHERE date_in BETWEEN 2002 AND 1983

A:

2012-02-08 isn't a date, it's an integer calulation that yield the result 2002.  This is then implictly cast into a date, with 2002 meaning 2002 days from the base date
Instead, use '2012-02-08' which is a string, which is also implicitly cast into a date, but the one you want.
SELECT * FROM wp_races_entry WHERE date_in BETWEEN '2012-02-08' AND '2012-02-27'

