Just to throw in another option...
Whilst I prefer the DateTime method posting here, I didn't like the fact it displayed 0 years etc.
/*
* Returns a string stating how long ago this happened
*/
private function timeElapsedString($ptime){
$diff = time() - $ptime;
$calc_times = array();
$timeleft = array();
// Prepare array, depending on the output we want to get.
$calc_times[] = array('Year', 'Years', 31557600);
$calc_times[] = array('Month', 'Months', 2592000);
$calc_times[] = array('Day', 'Days', 86400);
$calc_times[] = array('Hour', 'Hours', 3600);
$calc_times[] = array('Minute', 'Minutes', 60);
$calc_times[] = array('Second', 'Seconds', 1);
foreach ($calc_times AS $timedata){
list($time_sing, $time_plur, $offset) = $timedata;
if ($diff >= $offset){
$left = floor($diff / $offset);
$diff -= ($left * $offset);
$timeleft[] = "{$left} " . ($left == 1 ? $time_sing : $time_plur);
}
}
return $timeleft ? (time() > $ptime ? null : '-') . implode(' ', $timeleft) : 0;
}