I am facing problem when i'm trying to select records from a table between two dates.
m using the following query
select * from xxx where dates between '10/10/2012' and '10/12/2012'
this query works for me but when the dates are in format like 1/1/2013.. it doesn't work..
plz solve my problem ASAP.
Try this:
It works perfectly :)
By default Mysql store and return ‘date’ data type values in “YYYY/MM/DD” format. So if we want to display date in different format then we have to format date values as per our requirement in scripting language
And by the way what is the column data type and in which format you are storing the value.
I always use
YYYY-MM-DD
in my views and never had any issue. Plus, it is readable and non equivocal.You should be aware that using
BETWEEN
might not return what you expect with aDATETIME
field, since it would eliminate records dated'2012-10-12 08:00'
for example.I would rather use
where dates >= '2012-10-10' and dates < '2012-10-13'
(lower than next day)This solution provides CONVERT_IMPLICIT operation for your condition in predicate
OR
Demo on SQLFiddle