Hi there.
We are using the code below to show the amount of years, months, days, weeks, hours and minutes since a date.
We only want the relevant one to show, so if the start date was only a few minutes ago - it should only show minutes, not the others if they're 0.
The following code gives no errors, it simply doesn't echo anything.
Any help appreciated!
$original = strtotime($user['joined']);
function time_since($original) {
$chunks = array(
array(60 * 60 * 24 * 365 , 'year'),
array(60 * 60 * 24 * 30 , 'month'),
array(60 * 60 * 24 * 7, 'week'),
array(60 * 60 * 24 , 'day'),
array(60 * 60 , 'hour'),
array(60 , 'minute'),
);
$today = time(); /* Current unix time */
$since = $today - $original;
if($since > 604800) {
$print = date("M jS", $original);
if($since > 31536000) {
$print .= ", " . date("Y", $original);
}
}
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
if (($count = floor($since / $seconds)) != 0) {
// DEBUG print "<!-- It's $name -->\n";
break;
}
}
$print = ($count == 1) ? '1 '.$name : "$count {$name}s";
}
To echo it:
<li><span><strong><?php echo $print; ?></strong> ago</span></li>