Search code examples
phplaravelphp-carbon

Get day from date Laravel


I got a date with format 'Y-m-d', and want to get the day from it. Like if I have 2021.01.01, I want for example Friday, or Thursday depending on what day it actually is. I already got the date stored as $date and I want the day stored as $day.

I've already tried this, without any error, and without anything happening:

$day = Carbon::createFromFormat('Y-m-d', $date)->format('1');
var_dump($day);

Solution

  • I've found another solution for you :

    $timestamp = strtotime('2009-10-22');
    $day = date('l', $timestamp);
    echo $days;
    

    output:

    Thursday