Search code examples
laravelphp-carbon

How can I get created_at month name on laravel blade?


I have created_at field. on my database, and I need to get the month name, for example;

...
{{\Carbon\Carbon::now()->monthName}}
...

So how can I do it for $value->created_at?

I tried some solutions but didn't get the month name.


Solution

  • created_at already a Carbon instance, so you can do that by :

    {{ $value->created_at->format('F') }}
    

    Or,

    {{ \Carbon\Carbon::parse($value->created_at)->format('F') }}
    
    • F - A full textual representation of a month (January through December)
    • M - A short textual representation of a month (Jan through Dec)

    Translate to other language : You can use carbon to format your local language, as for Russian language :

    @php
       \Carbon\Carbon::setLocale('ru');
    @endphp
    
    {{ \Carbon\Carbon::parse($value->created_at)->translatedFormat('F') }}
    // output : ноябрь