Definition:
function human_time_diff( $from, $to = '' ) {}
Determines the difference between two timestamps.
The difference is returned in a human readable format such as "1 hour", "5 mins", "2 days".
Parameters
- int $from: Unix timestamp from which the difference begins.
- int $to: Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
Return values
returns:Human readable time difference.
Source code
function human_time_diff( $from, $to = '' ) { if ( empty($to) ) $to = time(); $diff = (int) abs($to - $from); if ($diff <= 3600) { $mins = round($diff / 60); if ($mins <= 1) { $mins = 1; } /* translators: min=minute */ $since = sprintf(_n('%s min', '%s mins', $mins), $mins); } else if (($diff <= 86400) && ($diff > 3600)) { $hours = round($diff / 3600); if ($hours <= 1) { $hours = 1; } $since = sprintf(_n('%s hour', '%s hours', $hours), $hours); } elseif ($diff >= 86400) { $days = round($diff / 86400); if ($days <= 1) { $days = 1; } $since = sprintf(_n('%s day', '%s days', $days), $days); } return $since; }
1959
Trackbacks/Pingbacks
[…] Human Readable Form (Facebook Style) – Tech Thought WordPress uses the human_time_diff() function: human_time_diff | A HitchHackers guide through WordPress __________________ 301tool 1.1.3 – URL redirector & shortener (PHP/MySQL) Can be hosted on […]