DEV Community

Morcos Gad
Morcos Gad

Posted on

The Wonderful Carbon - Laravel

Today I am talking about a great simple PHP API extension for DateTime that we use a lot in our projects, but I wanted to have a closer look at it.

At first we go to https://carbon.nesbot.com/ Here we will see a lot of interesting information and go deeper into it
See also https://github.com/briannesbitt/Carbon

  • See a short tip on the benefit
$user->created_at->diffForHumans();
=> "17 hours ago"

$user->created_at->diffForHumans([
     'parts' => 2
]);
=> "17 hours 54 minutes ago"

$user->created_at->diffForHumans([
     'parts' => 3
     'join' => ', ',
]);
=> "17 hours, 54 minutes, 50 seconds ago"

$user->created_at->diffForHumans([
     'parts' => 3,
     'join' => ', ',
     'short' => true,
]);
=> "17h, 54m, 50s ago"
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed the article and I hope you always enjoy the code .

Top comments (0)