I need to compare dates in MySQL ignoring the time portion in a DateTime
column. I have tried the following SQL.
SELECT * FROM order_table where order_date=date_format('2012-05-03', '%Y-%m-%d');
It doesn't retrieve any row even though there is a date 2012-05-03 10:16:46
in MySQL table. How can the time portion in the DateTime
field be ignored while comparing dates in MySQL?
If you want to pass in a date then you can try something like this:
You can look at this for more functions.
You could use the
DATE
function:But this is more efficient, if your table is large and you have an index on
order date
:Maybe, you can use function like
date()
. But in this case speed can be decreased, because index cannot be using. So, I recommend to useIn my case i had ,
DATE_FORMAT
andCONVERT_TZ
The only one worked for me is this
This is bit old .... but a correct answer also is using the date_format at the column order_date like below: