This question already has an answer here:
Suppose if a date is in the format
2018-10-10 16:24:52
How to get time ago format for this date as
2 days ago
..
If date format is 2018-09-10 16:24:52
The date format should be 1 month ago
and if 2017-10-10 16:24:52
The date format should be 1 year ago
How to achieve this in PHP?
</div>
Try this library - https://github.com/jenssegers/date
From README.md
-
Get a human readable output (alias for diffForHumans):
echo $date->ago(); // 5 days ago