How can I get created_at month name on laravel blade?

Viewed 6106

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.

4 Answers

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 : ноябрь

you can try as created_atalready a Carbon instance, so you can use this

{{ $value->created_at->monthName }}

make sure $value is a instance of Illuminate\Database\Eloquent\Model;

if it is not a instance of laravel model then you can do like this

{{ \Carbon\Carbon::parse($value->created_at)->monthName }} 

you can write by

{{ date('F', strtotime($value->created_at)) }}

you can get the name of month by the following code:

    {{ date("F", strtotime($value->created_at)) }}

you can get more details from (php website)

Related