$dates = [
['07.02.2019 22:10:56', '28.02.2019 23:59:59'],
['01.03.2019 00:00:00', '31.03.2019 23:59:59'],
['01.04.2019 00:00:00', '22.04.2019 19:22:35'],
];
<?php
function generateDatesRange($from, $to)
{
$from = new \DateTime($from);
$to = new \DateTime($to);
$start = new \DateTime($from->format('01.m.Y 00:00:00'));
$dates = [];
while ($start <= $to) {
$dates[] = $start->format('d.m.Y 00:00:00');
$dates[] = $start->format('t.m.Y 23:59:59');
$start->modify('+1 month');
}
$dates[0] = $from->format('d.m.Y H:i:s');
$dates[count($dates) - 1] = $to->format('d.m.Y H:i:s');
return array_chunk($dates, 2);
}
$from = '07.02.2019 22:10:56';
$to = '22.04.2019 19:22:35';
$result = generateDatesRange($from, $to);
print_r($result);
php index.php
Array
(
[0] => Array
(
[0] => 07.02.2019 22:10:56
[1] => 28.02.2019 23:59:59
)
[1] => Array
(
[0] => 01.03.2019 00:00:00
[1] => 31.03.2019 23:59:59
)
[2] => Array
(
[0] => 01.04.2019 00:00:00
[1] => 22.04.2019 19:22:35
)
)