Directly convert created_at date to human readable format

Did you know you can directly convert created_at date to human readble format like 1 miniute ago, 1 month ago using diffForHumans() function. Laravel eloquent by default enables Carbon instance on created_at field.

1$post = Post::whereId($id)->first();
2$result = $post->created_at->diffForHumans();
3 
4/* OUTPUT */
5// 1 Minutes ago, 2 Week ago etc..as per created time

Tip given by @vishal__2931

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord