-1

Possible Duplicate:
PHP How to find the time elapsed since a date time?

I have the following which produces MONTH YEAR.

<?php echo date('F Y', strtotime($video['Video']['posted_date'])); ?>

I'd like this to output to "Time" ago. i.e 3 hours ago, 6 months ago, 2 years ago. Any help will be very much appreciated. Thanks Andy

Community
  • 1
  • 1
Andrew Findlay
  • 131
  • 1
  • 7

3 Answers3

1
$now            = new DateTime(date("Y-m-d H:i:s"));
$videoPosted    = new DateTime($video['Video']['posted_date']);
$interval       = $now->diff($videoPosted);

echo $interval->format('%h hours, %m month and %d days ago');

Use only if PHP version > 5.3

edwardmp
  • 6,339
  • 5
  • 50
  • 77
0

If you use php 5.3+, you are looking for DateInterval::format()

pozs
  • 34,608
  • 5
  • 57
  • 63
-1

this will help you to calculate date difference: How to calculate the difference between two dates using PHP?

and after that you can convert the result using strtotime()

Community
  • 1
  • 1
Serg
  • 606
  • 3
  • 10