Possible Duplicate:
How to look which room is available between 2 dateTimes
I have this row of data
|room_id|checkin |checkout |
+ + + +
|1 |2012-05-02 |2012-05-09|
But I don’t want to choose this row which betweeen two dates
I have this query
SELECT *
FROM `reservations` `res`
WHERE (2012-05-03
NOT BETWEEN res.expected_checkin_date AND res.expected_checkout_date)
AND COALESCE(2012-05-08
NOT BETWEEN res.expected_checkin_date AND res.expected_checkout_date)
However, I am still getting this row which is not suppposed to come up. Actually, my idea is to choose all rows which is not between these two date. Any idea?
Update 1
Basically, someone is trying to reserve a room from 5/3 to 5/8 and I want to see a list of rooms that would meet that criteria.
Don’t know what types are
checkinandcheckout, whether strings or dates/datetimes, the issue seems to have to do with the fact your date constants are not delimited with single quotes (i.e. they are not represented as strings, as they should have been.)So, just try the following instead of your query: