Skip to content

Instantly share code, notes, and snippets.

@mknparreira
Last active August 12, 2021 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mknparreira/11a330a1d2da281980a21e6483aeb276 to your computer and use it in GitHub Desktop.
Save mknparreira/11a330a1d2da281980a21e6483aeb276 to your computer and use it in GitHub Desktop.
Laravel | Getting all months between 2 dates Carbon
public function getMonthListFromDate(Carbon $start)
{
    $start = $start->startOfMonth();
    $end   = Carbon::today()->startOfMonth();

    do
    {
        $months[$start->format('m-Y')] = $start->format('F Y');
    } while ($start->addMonth() <= $end);

    return $months;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment