3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php //$datetimeStart1 = new DateTime('2017-05-16'); //$datetimeEnd1 = new DateTime('2017-07-19'); //$datetimeStart2 = new DateTime('2017-07-12'); //$datetimeEnd2 = new DateTime('2017-07-22'); $datetimeStart1 = DateTime::createFromFormat('Y-m-d','2017-05-16'); $datetimeEnd1 = DateTime::createFromFormat('Y-m-d','2017-07-19'); $datetimeStart2 = DateTime::createFromFormat('Y-m-d','2017-07-12'); $datetimeEnd2 = DateTime::createFromFormat('Y-m-d','2017-07-22'); // following http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap if ($datetimeStart1 < $datetimeEnd2 && $datetimeEnd1 > $datetimeStart2) { echo min($datetimeEnd1,$datetimeEnd2)->diff(max($datetimeStart2,$datetimeStart1))->days+1; } else { echo 'no overlap'; }
based on q1mG2
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
8