Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql date function not working for less than

I need to get all records those equal and less than 2012-12-28 i used bellow query for this, booking_time is DATETIME field, and there are records less than 2012-12-28 but it returns zero rows. does anyone has idea ?

SELECT * FROM ctx_bookings WHERE DATE(booking_time)<=2012-12-28 ORDER BY id ASC 

Table filed

+---------------------+ | booking_time        | +---------------------+ | 2012-12-20 03:10:09 | | 2012-12-25 02:10:04 | +---------------------+ 

Please anybody know why is this happening ?

like image 750
Gihan Dilusha Avatar asked Dec 27 '12 07:12

Gihan Dilusha


1 Answers

wrap the value with single quote and surely it will work

SELECT *  FROM ctx_bookings  WHERE DATE(booking_time) <= '2012-12-28'  ORDER BY id ASC 
  • SQLFiddle Demo
like image 117
John Woo Avatar answered Oct 04 '22 19:10

John Woo