Consider someone booked a time slot for 5:00pm to 6:30pm. If another person is trying to book for 4:00pm to 5:30pm, booking should be made invalid selection. So how can we check the time slot is already taken, using sql.
CodePudding user response:
Let's assume the name of the table is bookings
and time columns are starttime
and endtime
if you wanna check your desired end time or start time is within any pre-booked time slot or not you can run below query.
If below query returns any row then it's been taken.
select * from bookings
where ('4:00pm' between starttime and endtime)or
('5:30pm' between starttime and endtime) or
('4:00pm' =<starttime and '5:30pm' >=endtime)
CodePudding user response:
You can simply use below query:
SELECT *
FROM bookings
WHERE '4:00pm' <= enddate
AND '5:30pm'>= startdate;