Laravel Carbon Get Previous Month Example

Laravel Carbon Get Previous Month Example

Hello friends, Today i will explain Laravel Carbon Get Previous Month Example. Also i will show how to get last month using carbon in laravel. In this example you learn  laravel carbon get previous month.

In this post we will get previous month in laravel. Here you can see that it is last month in the Carbon\Carbon class.

Read Also :  Laravel 8 Resource Route Controller Example

First example in numeric month output like “8” and second example in month name in string for example “August”.

Read also : Laravel Carbon Get Tomorrow Date Example

Laravel  Carbon Get Previous Month Name in Numeric

public function getLastMonth()
{
    $date = \Carbon\Carbon::now();

    $lastMonth =  $date->subMonth()->format('m'); // 8
    
    dd($lastMonth);

}

Laravel  Carbon Get Previous Month Name in String

public function getLastMonth()
{
    
    $date = \Carbon\Carbon::now();

    $lastMonth =  $date->subMonth()->format('F'); // August

    dd($lastMonth);

}

I hope you understand of Laravel  Carbon Get Last Month and it can help you…

Read Also :  Laravel Livewire Change Event Example