Slightly modified answer from above:
$commentTime = strtotime($whatever)
$today = strtotime('today');
$yesterday = strtotime('yesterday');
$todaysHours = strtotime('now') - strtotime('today');
private function timeElapsedString(
$commentTime,
$todaysHours,
$today,
$yesterday
) {
$tokens = array(
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
$time = time() - $commentTime;
$time = ($time < 1) ? 1 : $time;
if ($commentTime >= $today || $commentTime < $yesterday) {
foreach ($tokens as $unit => $text) {
if ($time < $unit) {
continue;
}
if ($text == 'day') {
$numberOfUnits = floor(($time - $todaysHours) / $unit) + 1;
} else {
$numberOfUnits = floor(($time)/ $unit);
}
return $numberOfUnits . ' ' . $text . (($numberOfUnits > 1) ? 's' : '') . ' ago';
}
} else {
return 'Yesterday';
}
}