To my knowledge, PHP does not provide such a built-in function.
But you can easily achieve this with a DateTime object:
$interval = '2016-11-01 10:00:00 till 2016-11-03 18:00:00'; $dates = explode(' till ', $interval); if(count($dates) == 2) { $current = $begin = new DateTime($dates[0]); $end = new DateTime($dates[1]); $intervals = []; // While more than 1 day remains while($current->diff($end)->format('%a') >= 1) { $nextDay = clone $current; $nextDay->setTime(23,59,59); $intervals []= [ 'begin' => $current->format('Ymd H:i:s'), 'end' => $nextDay->format('Ymd H:i:s'), ]; $current = clone $nextDay; $current->setTime(0,0,0); $current->modify('+1 day'); } // Last interval : from $current to $end $intervals []= [ 'begin' => $current->format('Ymd H:i:s'), 'end' => $end->format('Ymd H:i:s'), ]; print_r($intervals); }
source share