Using Carbon to return a human readable datetime difference

By default, Eloquent will convert the created_at, updated_at, and deleted_at columns to instances of Carbon. So, your code should be just like this:

$comment->created_at->diffForHumans();

It's very cool. It'll produce string like 2 minutes ago or 1 day ago. Plurar or singular, seconds, minutes, hours, days, weeks, or years, it runs automatically. I've tested it on Laravel version 4.1.24.


If you read the Carbon docs to get what you want you call the diffForHumans() method.

<?php echo \Carbon\Carbon::createFromTimeStamp(strtotime($comment->created_at))->diffForHumans() ?>

For any version of Laravel

$message->updated_at->diffForHumans();