here's a function i wrote a while ago,
function timeago($time) {
//Find difference in seconds
$d = time()-$time;
//Second(s)
if ($d < 60) {
return $d." second".(($d==1)?'':'s')." ago";
} else {
//Minute(s)
$d = round($d / 60);
if($d < 60) {
return $d." minute".(($d==1)?'':'s')." ago";
} else {
//Hour(s)
$d = round($d / 60);
if($d < 24) {
return $d." hour".(($d==1)?'':'s')." ago";
} else {
//Day(s)
$d = round($d / 24);
if($d < 7) {
return $d." day".(($d==1)?'':'s')." ago";
} else {
//Week(s)
$d = round($d / 7);
if($d < 1) {
return $d." week ago";
}
}
}
}
}
}
here's a another one from the comments in time() from php.net
public static function distanceOfTimeInWords($fromTime, $toTime = 0, $showLessThanAMinute = false) {
$distanceInSeconds = round(abs($toTime - $fromTime));
$distanceInMinutes = round($distanceInSeconds / 60);
if ( $distanceInMinutes <= 1 ) {
if ( !$showLessThanAMinute ) {
return ($distanceInMinutes == 0) ? 'less than a minute' : '1 minute';
} else {
if ( $distanceInSeconds < 5 ) {
return 'less than 5 seconds';
}
if ( $distanceInSeconds < 10 ) {
return 'less than 10 seconds';
}
if ( $distanceInSeconds < 20 ) {
return 'less than 20 seconds';
}
if ( $distanceInSeconds < 40 ) {
return 'about half a minute';
}
if ( $distanceInSeconds < 60 ) {
return 'less than a minute';
}
return '1 minute';
}
}
if ( $distanceInMinutes < 45 ) {
return $distanceInMinutes . ' minutes';
}
if ( $distanceInMinutes < 90 ) {
return 'about 1 hour';
}
if ( $distanceInMinutes < 1440 ) {
return 'about ' . round(floatval($distanceInMinutes) / 60.0) . ' hours';
}
if ( $distanceInMinutes < 2880 ) {
return '1 day';
}
if ( $distanceInMinutes < 43200 ) {
return 'about ' . round(floatval($distanceInMinutes) / 1440) . ' days';
}
if ( $distanceInMinutes < 86400 ) {
return 'about 1 month';
}
if ( $distanceInMinutes < 525600 ) {
return round(floatval($distanceInMinutes) / 43200) . ' months';
}
if ( $distanceInMinutes < 1051199 ) {
return 'about 1 year';
}
return 'over ' . round(floatval($distanceInMinutes) / 525600) . ' years';
}