I am developing a car rental system where people can book a car in this page.
So I need to know how to search using the customer's date range (rent and return) from the booking table.
I have this table:
CREATE TABLE `autos_bookings` ( `id` int(11) NOT NULL, `booking_id` int(11) NOT NULL DEFAULT '0', `auto_id` int(11) NOT NULL DEFAULT '0', `date_out` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `date_return` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `autos_bookings` ADD PRIMARY KEY (`id`); ALTER TABLE `autos_bookings` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
So, what I want to do is have another date range (for example, let's say: $dateclientewantsrent
and $dateclientewantsreturn
) and search that table to see if there are any existing Booking.
SELECT * FROM `autos_bookings` WHERE SOMETHING
Two ranges overlap when each range start point is smaller than the opposite range end point. Right now