Skip to content

Instantly share code, notes, and snippets.

@engelcituk
Last active January 28, 2021 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save engelcituk/e4cc0e8db2c85bf58e2eb731c622656a to your computer and use it in GitHub Desktop.
Save engelcituk/e4cc0e8db2c85bf58e2eb731c622656a to your computer and use it in GitHub Desktop.
Formatos de fecha con carbon en laravel
$date = Carbon::now();
echo $date->toDateString();
// 2020-06-22
echo $date->toDateTimeString();
// 2020-06-22 19:45:23
echo $date->toFormattedDateString();
// Jun 22, 2020
echo $date->toTimeString();
// 19:45:23
echo $date->toDayDateTimeString();
// Mon, Jun 22, 2020 7:45 PM
echo Carbon::now()->subDays(5)->diffForHumans();
// 5 days ago
echo Carbon::now()->subDays(24)->diffForHumans();
// 3 weeks ago
echo Carbon::now()->subMonth()->diffForHumans();
// 1 month ago
echo Carbon::create('2020')->longRelativeDiffForHumans('2018');
// 5 months 3 weeks 19 hours 40 minutes 54 seconds ago
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment