Laravel Carbon Get Last Day of Month Example
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...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial