I have a start and end DateTime object and want to iterate over them to get an array of start and end per day. To iterate over it I wrote this function:
public function getDatesBetweenTwoDates($start = null, $end = null)
{
return iterator_to_array(new \DatePeriod($start, new \DateInterval('P1D'), $end));
}
However, this function returns an array like this and does not support times:
['2017-10-01', '2017-10-02', ...]
What I need is something like this:
Input:
$start = new DateTime("2017-10-01 10:00:00");
$end = new DateTime("2017-10-03 19:00:00");
Output:
[
[
'start' => '2017-10-01 10:00:00',
'end' => '2017-10-01 23:59:59'
],
[
'start' => '2017-10-02 00:00:00',
'end' => '2017-10-02 23:59:59'
],
[
'start' => '2017-10-03 00:00:00',
'end' => '2017-10-03 19:00:00'
],
]
Any hint or help would be highly appreciated.