I need to check whether an entered time range overlaps with another time range This thread PHP function to check time between the given range? gives a simple explanation on how to check if one date is with a range
I altered the second example function/if-case to the following:
if(check_slot_range('2014-06-26 06:00:00','2014-06-26 10:00:00', '2014-06-26 07:00:00') OR check_slot_range('2014-06-26 06:00:00','2014-06-26 10:00:00', '2014-06-26 09:00:00')){
echo "OVERLAP";
}else{
echo "NO OVERLAP";
}
Only the following give an overlap:
Range '2014-06-26 07:00:00' to '2014-06-26 09:00:00'
Range '2014-06-26 05:00:00' to '2014-06-26 09:00:00'
Range '2014-06-26 07:00:00' to '2014-06-26 11:00:00'
This one does not throw the overlap:
- Range '2014-06-26 05:00:00' to '2014-06-26 11:00:00'
How do I need to change the if-clause to catch the overlap for the last example?
For clarification, here the function to compare
function check_slot_range($start_date, $end_date, $todays_date)
{
$start_timestamp = strtotime($start_date);
$end_timestamp = strtotime($end_date);
$today_timestamp = strtotime($todays_date);
return (($today_timestamp >= $start_timestamp) && ($today_timestamp <= $end_timestamp));
}