/ Published in: PHP
Original script by jaytee. I used the script in a project, but then needed 'future' support. Added the script, thought I would share.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function relative_time($date) { if ($diff>0) { if ($diff<60) return $diff . " second" . plural($diff) . " ago"; if ($diff<60) return $diff . " minute" . plural($diff) . " ago"; if ($diff<24) return $diff . " hour" . plural($diff) . " ago"; if ($diff<7) return $diff . " day" . plural($diff) . " ago"; if ($diff<4) return $diff . " week" . plural($diff) . " ago"; } else { if ($diff>-60) return "in " . -$diff . " second" . plural($diff); if ($diff>-60) return "in " . -$diff . " minute" . plural($diff); if ($diff>-24) return "in " . -$diff . " hour" . plural($diff); if ($diff>-7) return "in " . -$diff . " day" . plural($diff); if ($diff>-4) return "in " . -$diff . " week" . plural($diff); } }