Search between two date ranges
P粉884548619
P粉884548619 2024-04-03 11:56:15
0
1
553

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

P粉884548619
P粉884548619

reply all(1)
P粉118698740

Two ranges overlap when each range start point is smaller than the opposite range end point. Right now

...
WHERE booking.date_out 

Depending on the logic, one or both comparisons may be weak.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template