Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alfie's avatar
Level 3

Carbon date Language

Hey all!

Im having this language issue while using Carbon Carbon::parse($this->updated_at)->locale('es')->format("l j F Y"); still prints the month and day in english despite setting the locale to spanish here and on my config.app file.

Any ideas what i could do to present it like this: [Month in spanish] 09 2021

if i use ->locale('es')->monthNameit works fine but not with the format tag.

0 likes
2 replies
Alfie's avatar
Level 3

Found 2 solutions for anyone requiring this in the future:

return Carbon::parse($this->updated_at)->translatedFormat('d F Y'); //09 junio 2021

or 

setlocale(LC_TIME, 'es_ES');
return Carbon::parse($this->updated_at)->formatLocalized('%d %B %Y'); //09 junio 2021
2 likes
Elaniin's avatar

In addition there is also another way:

return ucfirst(Carbon::parse($this->updated_at)->isoFormat('dddd D [de] MMMM [de] YYYY')); // Miércoles 09 de junio de 2021

Please or to participate in this conversation.