Carbon - get first day of month

Lovelock picture Lovelock · Jun 3, 2015 · Viewed 72.2k times · Source

I am using carbon but trying to get the first day of the month so I can run a report from the beginning of the month till the current day.

    $date = [
        'start' => new \Carbon\Carbon('last month'),
        'end' => new \Carbon\Carbon('today')
    ];

The above code will show todays date back to same date in the previous month. But I want to get from the 1st to now.

Is there an easy way to do this like I am above? Cant find anything in the docs.

Answer

Shriganesh Shintre picture Shriganesh Shintre · Jul 29, 2015

You can use following function

$start = Carbon::now()->startOfMonth();
$end = Carbon::now();