Reputation: 31
I have a table that contain two datetime field. So when I going to search anything betwwn two dates then it do not show exact result. It suffering me more when I want to see only one day search result. My code is
SELECT * FROM item WHERE production_date BETWEEN $a AND $b
Upvotes: 2
Views: 5222
Reputation: 3576
You need to CAST
your production_date as DATE
like this, otherwise BETWEEN
will get exclusive instead inclusive.
SELECT * FROM item WHERE DATE(production_date) BETWEEN $a AND $b
I'm not sure if your column has a time component, truncate it out with DATE(column)
but if it does, this should do the trick.
Upvotes: 7
Reputation: 291
You are using datetime as the type for your field. Change it to only date and it will works fine!
Or you can use '2014-05-27 00:00:00' as start date and '2014-05-28 23:59:59' as your end date. Means add some extra string with your variable.
Upvotes: -1