Laravel 8 Carbon Get Day from Date Example


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


Hi Artisan,

In This example, I will share with you how to get the day name from date in laravel 8 in laravel using carbon in laravel so it can easy to use in laravel app.

Here, how to get day name from date in laravel 8, laravel 8 carbon get day name from date, laravel carbon gets day name from number, get day name from date laravel, laravel 8 carbon get day from date.

Let's see a full example of how to get day name from date laravel.

Example : 1
<?php

namespace App\Http\Controllers;

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

class HomeController extends Controller
{
    /**
     * laravel carbon current date time..
     *
     * @return string
    */
    public function index()
    {
        $myDate = '08/20/2021';
        $date = Carbon::createFromFormat('m/d/Y', $myDate)->format('l');
   
        var_dump($date);
    }

}
Output
string(6) "Monday"
Example : 2
<?php

namespace App\Http\Controllers;

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

class HomeController extends Controller
{
    /**
     * laravel carbon current date time..
     *
     * @return string
    */
    public function index()
    {
        $date = Carbon::now();

        $dayName = $date->format('l');
        
        var_dump($dayName);
    }

}
Output
string(7) "Tuesday"

It Will Help You..

Share: