sql - MySQL query to check if a date range is available -
i have checkout dates slot whether available or not, particular id. have tried following query failed cover cases. let me clear scenario first. let's say:
id booked_from booked_to 2014-12-20 2014-12-29
if try book 2014-12-22 2014-12-24
conflicts above mentioned record.
i using following query , working fine above mentioned scenario
select * `tablename` `id` ='a' , ( (`booked_from` <= '2014-12-22' , `booked_till`>= '2014-12-22') or (`booked_from` <= '2014-12-24' , `booked_till`>= '2014-12-24') ) , `ad_status` != 2
but if specify 2014-12-15 2015-01-05
shows id available when overlaps example record.
what must apply cover remaining issue also. stuck this. appreciated. in advance.
this query select rows dates overlap range [2014-12-22 ... 2014-12-24]
, dates inclusive:
select * `tablename` `id` ='a' , `ad_status` != 2 , '2014-12-24' >= `booked_from` , `booked_till` >= '2014-12-22'
if there no mathing rows can assume room available. query explained here.
Comments
Post a Comment