Carbon Dates with Laravel Blade

Written by SarahS

23rd September 2019

So, if you’re displaying something like posts or tasks on your site and you want to know how long ago they were created, then you’ll probably be pulling back the created_at date with something like this:

{{ $task->created_at }}

and it comes out on your page looking like this:

2019-09-11 10:26:21

If you’d prefer to show something more user-friendly then use Carbon (which is already in Laravel):

{{ $task->created_at->diffForHumans() }}

and instead you’ll get:

1 week ago

For more information about all the wonderful things you can do with Carbon, go here:

This is one of my Laravel posts.  I’m still learning Laravel so the posts are usually pretty basic and are more aimed at keeping track of things that I find useful so that I can come back to them again at a later date.  I hope you find them useful too.  If not, or if you think they are wrong then please leave a comment below.  Thank you.

Faster Laravel Hosting

If this post helped you or if you have any questions please leave me a comment below:


Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

Setting up SQLite for Laravel

Setting up SQLite for Laravel

Sometimes you may decide you want to use SQLite for your Laravel app instead of a full blown MySQL database. In that...