I'm stuck with a SQL query.
I have a situation like this: in the bookings
table. I have two simple DATETIME
columns date_start
and date_end
, and I have two datepickers where the user can select those two dates and values from them we should call dp_date_start
and dp_date_end
.
Rows in the result set need to fit into following criteria:
- if
date_start
anddate_end
are completely inside that range - if only
date_start
ordate_end
are in that range - if
date_start
ordate_end
are border values
Basically it's a booking logic, imagine it that's a room that cannot be booked if it's already occupied.
What I have tried so far:
SELECT *
FROM bookings
WHERE 'dp_date_start' BETWEEN start_date AND end_date
OR 'dp_date_end' BETWEEN start_date AND end_date
OR start_date BETWEEN 'dp_date_start' AND 'dp_date_end'
OR end_date BETWEEN 'dp_date_start' AND 'dp_date_end';
But if fails if i.e. 'dp_date_start'
is equal to end_date
.
Thanks in advance!