Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Query not getting executing - returns empty set

Tags:

sql

mysql

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.

like image 726
Sangam_cs Avatar asked Jan 27 '26 18:01

Sangam_cs


1 Answers

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
like image 103
Mark Byers Avatar answered Jan 30 '26 10:01

Mark Byers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!