Laravel Carbon Get Last Day of Month Tutorial


Share:
Published By: Admin, Published On: Sep 24, 2021, Category: PHP Laravel 8 Laravel


Hi Artisan,

Today, In This example, I will share with you how to get the last day of the month in laravel using carbon in laravel so it can easy to use in laravel app.

So, I will tell something carbon provided inbuilt function endOfMonth so I will use this function and get last day of the month in laravel carbon.

Here, laravel carbon get last day of month, get last day of the month in laravel, get last day of month carbon, PHP carbon get last day of the month, laravel carbon endOfMonth, laravel carbon end of the month.

Let's see I will show you a full example of get the last day of month in laravel using carbon so follow mine below code.

Example:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Carbon\Carbon;

class HomeController extends Controller
{
    /**
     * laravel carbon get last day of the month...
     *
     * @return string
    */
    public function index()
    {
        $myDate = '01/01/2021';
        $date = Carbon::createFromFormat('m/d/Y', $myDate)
                        ->endOfMonth()
                        ->format('Y-m-d');
  
        var_dump($date);
    }

}
Output
string(10) "2021-01-31"

It Will Help You..

Share: