Laravel Carbon Get Last Day of Month Example

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share
Laravel Carbon Get Last Day of Month Example

Hello Dev’s
Today now in this blog, i will show you how to get last day of month in laravel application. Here we must need to get last day of current month by using Carbon in laravel application.

Here I am using the carbon package and here i am trying to get the last date of the current month. So it is very easy and simply to get current month of last day by using carbon in laravel. So we will see it the bellow example.

Example 1 :
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function getLastDay()
{
    $today = \Carbon\Carbon::now(); //Current Date and Time

    $lastDayofMonth =    \Carbon\Carbon::parse($today)->endOfMonth()->toDateString();

    dd($lastDayofMonth);
}
Example 2 :
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function getLastDay()
{
    $lastDayofMonth = \Carbon\Carbon::now()->endOfMonth()->modify('0 month')->toDateString();

    dd($lastDayofMonth);
}
Example 3 :
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function getLastDay()
{
    $lastDayofMonth = \Carbon\Carbon::now()->endOfMonth()->toDateString();
    
    dd($lastDayofMonth);
}

Output :

"2021-04-31"

Read Also : How Laravel Livewire Click Event work?

I hope it will help you. Also you can follow us onĀ Facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →