Last active
January 28, 2021 22:09
-
-
Save engelcituk/e4cc0e8db2c85bf58e2eb731c622656a to your computer and use it in GitHub Desktop.
Formatos de fecha con carbon en laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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