-2

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 !

tereško
  • 58,060
  • 25
  • 98
  • 150
kadour Hk
  • 47
  • 4

1 Answers1

0

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.

Marcel
  • 4,854
  • 1
  • 14
  • 24