Level 53
Something like that:
public function weeksBetweenTwoDates($start, $end)
{
$weeks = [];
while ($start->weekOfYear !== $end->weekOfYear) {
$weeks[] = [
'from' => $start->startOfWeek()->format('Y-m-d'),
'to' => $start->endOfWeek()->format('Y-m-d')
];
$start->addWeek(1);
}
return $weeks;
}
$this->weeksBetweenTwoDates(Carbon::now(), Carbon::now()->addDays(16));
Results:
[
0 => [
"from" => "2019-09-16",
"to" => "2019-09-22"
],
1 => [
"from" => "2019-09-23",
"to" => "2019-09-29"
]
]
3 likes