- print_r: documentation ( source)
- explode: documentation ( source)
- strtotime: documentation ( source)
<?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);