Relative times for posts are off.
-
Hello. I’m switching over to relative times for my website and am having some trouble. For some reason, articles start at “Posted 4 hours ago” instead of “Posted less than a minute ago,” even if I did post the article just a minute ago.
The function I’m using is below:
if(!function_exists('how_long_ago')){ function how_long_ago($timestamp){ $difference = time() - $timestamp; if($difference >= 60*60*24*365){ // if more than a year ago the_date(); } elseif($difference >= 60*60*24*7*5){ // if more than five weeks ago $int = intval($difference / (60*60*24*30)); $s = ($int > 1) ? 's' : ''; $r = $int . ' month' . $s . ' ago'; } elseif($difference >= 60*60*24*7){ // if more than a week ago $int = intval($difference / (60*60*24*7)); $s = ($int > 1) ? 's' : ''; $r = $int . ' week' . $s . ' ago'; } elseif($difference >= 60*60*24){ // if more than a day ago $int = intval($difference / (60*60*24)); $s = ($int > 1) ? 's' : ''; $r = $int . ' day' . $s . ' ago'; } elseif($difference >= 60*60){ // if more than an hour ago $int = intval($difference / (60*60)); $s = ($int > 1) ? 's' : ''; $r = $int . ' hour' . $s . ' ago'; } elseif($difference >= 60){ // if more than a minute ago $int = intval($difference / (60)); $s = ($int > 1) ? 's' : ''; $r = $int . ' minute' . $s . ' ago'; } else { // if less than a minute ago $r = 'less than a minute ago'; } return $r; } }
Any ideas? Thanks.
- The topic ‘Relative times for posts are off.’ is closed to new replies.