here’s my contribution of the the_date_since function:
<code.
<?php
function the_date_since($before = ”, $after = ‘ago’, $echo = 1) {
global $post;
$output = $before;
$seconds = abs(time() – strtotime($post->post_date));
$minutes = floor($seconds/60);
$seconds -= $minutes * 60;
$hours = floor($minutes/60);
$minutes -= $hours * 60;
$days = floor($hours/24);
$hours -= $days * 24;
$weeks = floor($days/7);
$days -= $weeks * 7;
$months = floor($days/30); // 30 is decent, better than weeks/4…
$weeks -= $months * 30;
$years = floor($days/365); // good enough.
if ($years > 0)
$output .= “over “.$years.” year”.($years>1?’s, ‘:’, ‘);
if ($months > 0)
$output .= ($weeks>1?”:’and’).$months.” month”.($months>1?’s, ‘:’, ‘);
if ($weeks > 0)
$output .= ($days>1?”:’and’).$weeks.” week”.($weeks>1?’s, ‘:’, ‘);
if ($days > 0)
$output .= ($hours>1?”:’and’).$days.” day”.($days>1?’s, ‘:’, ‘);
if ($hours > 0)
$output .= ($minutes>1?”:’and’).$hours.” hour”.($hours>1?’s, ‘:’, ‘);
if ($minutes > 0)
$output .= ($seconds>1?”:’and’).$minutes.” minute”.($minutes>1?’s, ‘:’, ‘);
if ($seconds > 0)
$output .= ‘and ‘.$seconds.” second”.($seconds>1?’s ‘:’ ‘);
/*else
$output .= “just posted”;
*/
$output .= $after;
if ($echo) echo $output;
else return $output;
}
?>
it’s a combination of codegirl’s and david’s codes.
What does it do:
1) it will display years, months, days, hours, minutes and seconds….
2) it leaves out where the unit is 0
3) Includes david’s progressive division
4) Is smart enough to add an “and” before the last unit – ie, 4 Days, 3 hours, 25 minutes, and 12 seconds
TG