Using Carbon to manipulate date and time on laravel

Laravel comes with Carbon a PHP API Extension for DateTime – Out of the box.
It is easy to manipulate date and time on laravel using Carbon.
Laravel timestamps created_at and updated_at are by default Carbon instances.
We can add new fields by creating an array on Model :

Using Carbon is as simple as following :
Make sure the date is instance of carbon .
Then , using it to the view is easy.

{{ $user->birth_date->diffForHumans() }}

This will return like 1 years ago which is easily readable.

Sharing is caring!

Related Post