Comparing dates in MySQL ignoring time portion of a DateTime field

You could use the DATE function:

SELECT col1, col2, ..., coln
FROM order_table
WHERE date(order_date) = '2012-05-03'

But this is more efficient, if your table is large and you have an index on order date:

SELECT col1, col2, ..., coln
FROM order_table
WHERE order_date >= '2012-05-03'
AND order_date < '2012-05-04'

If you want to pass in a date then you can try something like this:

where YEAR(order_date)='2012' AND MONTH(order_date)='05' AND DAY(order_date)='03'

You can look at this for more functions.


@Mark has got the good approach but just be careful that you will always have to calculate and find next day in that case. If you want to avoid that and still ignore time you could do following:

WHERE order_date >= '2012-05-27 00:00:00' AND order_date <= '2012-05-27 23:59:59'

I hope this makes sense.


SELECT * FROM order_table WHERE date(order_date) = '2012-05-03';