Time I have in the following format<?= $post['created_at'] ?>
Output: 2018-08-03 11:44:59
How can coordination work like the following example : ago 2 month !
Time I have in the following format<?= $post['created_at'] ?>
Output: 2018-08-03 11:44:59
How can coordination work like the following example : ago 2 month !
I guess it 's less a matter of code igniter, butt rather a date time php thing. You can get it with the DateTime class of php.
$now = new \DateTime();
$then = new \DateTime('2018-08-03 11:44:59');
$difference = $nof->diff($then, true);
Now you hace the difference between now and then in a DateInterval object. With this you can easily display the difference in the format you want.
echo $difference->days . ' ago'; // n days ago
If you want to get exactly the number of weeks which run by, you have to do some math.
echo floor($now->diff($then, true)->days / 7);
Same works for every format you want. That 's it.