3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $fromDate = explode("-", '2017-01-28'); $toDate = explode("-", '2017-05-15'); $start = new DateTime('2017-01-28'); $start->modify('first day of this month'); $end = new DateTime('2017-05-15'); $end->modify('first day of next month'); $interval = DateInterval::createFromDateString('1 month'); $period = new DatePeriod($start, $interval, $end); foreach ($period as $dt) { $date = $dt->format("Y-m"); $firstDate = $date."-15"; $secondDate = $date."-28"; if((strtotime('2017-05-15') >= strtotime($firstDate)) && (strtotime('2017-01-28') <= strtotime($firstDate))) $res[] = $firstDate; if((strtotime('2017-05-15') >= strtotime($secondDate)) && (strtotime('2017-01-28') <= strtotime($secondDate))) $res[] = $secondDate; } print_r($res);
based on XmYGH
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0rc3
Array ( [0] => 2017-01-28 [1] => 2017-02-15 [2] => 2017-02-28 [3] => 2017-03-15 [4] => 2017-03-28 [5] => 2017-04-15 [6] => 2017-04-28 [7] => 2017-05-15 )