Im having a little problem with some MYSQL I have.
I need to be able to check if a period of time has already been booked in a holiday room.
My database uses DATETIME Fields and is set out like this:
Database image link, as my rep is low
I have a query like:
SELECT * FROM `caravanavail1`
WHERE (`checkIn` BETWEEN '2014-01-07 14:00:00' AND '2014-01-08 10:00:00')
OR (`checkOut` BETWEEN '2014-01-07 14:00:00' AND '2014-01-08 10:00:00')
I will always pass in two dates, however sometimes the dates may clash in many ways:
- The checkIn maybe in the middle of another holiday and the checkOut may not.
- The checkOut maybe in the middle of another holiday and the checkIn may not.
- They maybe identical dates to another holiday.
- The checkIn and checkOut dates I provide may BOTH be inside another booking.
I have been scratching my head for a few days with this, can anyone help me fix the SQL code above(I would prefer a single query, rather than two) to return what I need?