/ Published in: PHP
See http://codex.wordpress.org/Function_Reference/human_time_diff for Wordpress equivalent
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function timeAgo($timestamp, $granularity=2, $format='Y-m-d H:i:s'){ if($difference < 0) return '0 seconds ago'; elseif($difference < 864000){ $output = ''; foreach($periods as $key => $value){ if($difference >= $value){ $difference %= $value; $output .= ($output ? ' ' : '').$time.' '; $output .= (($time > 1 && $key == 'day') ? $key.'s' : $key); $granularity--; } if($granularity == 0) break; } return ($output ? $output : '0 seconds').' ago'; } } Call: $time = timeAgo($dateRef);
URL: http://www.phpsnippets.info/display-dates-as-time-ago