You can do a very simple check:
($dt1_1 <= $dt2_2) && ($dt1_2 >= $dt2_1)
Explanation:
10/05 15/05
[- $dt1_x -]
[--------------- $dt2_x ---------------]
18/04 23/10
-
$dt1_1
(10/05) is less than or equal to $dt2_2
(23/10)? yes
-
$dt1_2
(15/05) is greater than or equal to $dt2_1
(18/04)? yes
Both conditions are true , so the $dt1_1 -> $dt1_2
interval is contained in the $dt2_1 -> $dt2_2
range.
Example when false :
10/05 15/05
[- $dt1_x -]
[----------- $dt2_x ------------]
16/05 23/10
-
$dt1_1
(10/05) is less than or equal to $dt2_2
(23/10)? yes
-
$dt1_2
(15/05) is greater than or equal to $dt2_1
(16/05)? NOT
Code:
$dt1_1 = date("Y-m-d", strtotime(str_replace("/","-","10/05/2017")));
$dt1_2 = date("Y-m-d", strtotime(str_replace("/","-","15/05/2017")));
$dt2_1 = date("Y-m-d", strtotime(str_replace("/","-","18/04/2017")));
$dt2_2 = date("Y-m-d", strtotime(str_replace("/","-","23/10/2017")));
if(($dt1_1 <= $dt2_2) && ($dt1_2 >= $dt2_1)){
echo "True";
}else{
echo "False";
}
Note: The replaces
on dates are required: " #
Try Ideone .