Skip to content

Instantly share code, notes, and snippets.

@rdgutierrez
Last active February 14, 2024 20:30
Show Gist options
  • Save rdgutierrez/b06fae22348cd0376836 to your computer and use it in GitHub Desktop.
Save rdgutierrez/b06fae22348cd0376836 to your computer and use it in GitHub Desktop.
Fechas en español con Carbon en Laravel 5
Using a library as Laravel-Date you will just need to set the language of the app in the Laravel app config file and use its functions to format the date as you want.
Set the language in /app/config/app.php
...
'locale' => 'es',
...
I've found this library pretty useful and clean. To use it, you can write something like the example in the library readme file. I leave the results in spanish.
...
echo Date::now()->format('l j F Y H:i:s'); // domingo 28 abril 2013 21:58:16
echo Date::parse('-1 day')->diffForHumans(); // 1 día atrás
...
This is the link to the repository:
https://github.com/jenssegers/laravel-date
To install this library you can follow the instructions detailed in the following link:
https://github.com/jenssegers/laravel-date#installation
@jcq2003
Copy link

jcq2003 commented Feb 14, 2024

It is easier to set Date::now()->locale('es_PE')
to get same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment