3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $startDate = '2017-03-31'; $endDate = '2017-05-14'; $fromDate = explode("-", $startDate); $toDate = explode("-", $endDate); $start = new DateTime($startDate); $end = new DateTime($endDate); $interval = DateInterval::createFromDateString('1 month'); $period = new DatePeriod($start, $interval, $end); //print_r($interval); foreach ($period as $dt) { $date = $dt->format("Y-m-d"); print $date.'<br>'; $firstDate = $date."-15"; $secondDate = $date."-28"; if((strtotime($endDate) >= strtotime($firstDate)) && (strtotime($startDate) <= strtotime($firstDate))) $res[] = $firstDate; if((strtotime($endDate) >= strtotime($secondDate)) && (strtotime($startDate) <= strtotime($secondDate))) $res[] = $secondDate; } print_r($res);
based on l7jKC
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0alpha1
2017-03-31<br>2017-05-01<br>Array ( [0] => 2017-03-31-15 [1] => 2017-03-31-28 [2] => 2017-05-01-15 [3] => 2017-05-01-28 )