How can I check the date range

As you can see from the title, my question is quite difficult to express, but there is a problem:

I have a MySQL table with some data:

enter image description here

In the registration form, I must indicate the start and end times of the reservation. How can I check if there is an already registered reservation for a specified time or not. For example, I could not put a new reservation, which starts at 13:20 and ends at 15:00, etc.

+2
source share
2 answers

If the beginning or end of the new reservation that you want to create is within the current range, the reservation must be blocked. Using :reservationStart and :reservationEnd as these dates, you can request:

 SELECT * FROM reservations WHERE :reservationStart BETWEEN reservation_from AND reservation_to OR :reservationEnd BETWEEN reservation_from AND reservation_to OR 
+1
source

Use anti semi join, under request return numbers, which are available for booking within the specified registration and check-out limits. This is in Rails.

Communication

Reservation belongs to Room

The room has a lot of booking

Inquiry

check_in_at = '2016-12-28'

check_out_at = '2016-12-29'

Room.where.not ("EXISTS (SELECT a reservation) * From bookings, where rooms.id = bookings.room_id AND bookings.check_in_at BETWEEN AND AND? And bookings.check_out_at BETWEEN? AND?)", Check_in_at, check_out_at, check_in_at, check_out_at )

0
source

Source: https://habr.com/ru/post/1201333/


All Articles