Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Carbon's diffForHumans Formatting

I'm trying to implement a comment section in my project and want to show how long ago the comment was posted.

So i did:

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

And the output was

  3 hours from now 

But the output that i want is

3 hours ago 

Am i missing something ? I'm doing this in laravel

like image 994
Bigya Tuladhar Avatar asked Dec 08 '22 14:12

Bigya Tuladhar


1 Answers

You can use, this $comment->created_at->diffForHumans(null, true) to remove the ago,from now, etc then you can append the ago by yourself . So you'll end up with:

$comment->created_at->diffForHumans(null, true).' ago'

(NB: you may need to check why this does not work by default)

Ref: https://carbon.nesbot.com/docs/#api-humandiff

like image 65
Oluwatobi Samuel Omisakin Avatar answered Dec 23 '22 14:12

Oluwatobi Samuel Omisakin