Laravel Carbon Get Last Day of Month Example

Laravel 6 , PHP , Laravel , Laravel 7

Nicesnippets

24447

26-12-2019


Hi Guys,

In this blog i will teach you how to get last day month in laravel. We need to get last day of current month using Carbon in laravel.

I am using the carbon package and i am trying to get the last date of the current month. It is easy and simply to get current month last day using carbon in laravel. You can see 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 :

"2019-12-31"

It will help you...


Recommended Posts