php - Need to see if a range of dates overlaps another range of dates in sql -
i have table stores bookings of rooms, schema is:
id | room_id | check_in_date | check_out_date | user_id
i need run search query rooms available/unavailable between set range of dates.
also keep in mind there exists table holds dates when room prebooked , in format:
room_id | date
so need run query looks rooms available within set range, how formulate query? i'm using mysql here.
---edit---
theres rooms table of schema:
id | room details etc
the unavailability/prebooked dates table holds sporadic single dates, each date in unavailability table refers date when room reason cannot booked eg: maintenance etc
select room_id rooms r left join bookings b on ( r.room_id = b.room_id , b.check_in_date > '$max_date' , b.check_out_date < '$min_date' )
i'm not sure how pre-booked rooms factors in there no date range. pre-booked rooms entry on bookings or not?
Comments
Post a Comment