3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function ago($when) { $diff = date("U") - $when; // Days $day = floor($diff / 86400); $diff = $diff - ($day * 86400); // Hours $hrs = floor($diff / 3600); $diff = $diff - ($hrs * 3600); // Mins $min = floor($diff / 60); $diff = $diff - ($min * 60); // Secs $sec = $diff; // Return how long ago this was. eg: 3d 17h 4m 18s ago // Skips left fields if they aren't necessary, eg. 16h 0m 27s ago / 10m 7s ago $str = sprintf("%s%s%s%s", $day != 0 ? $day."d " : "", ($day != 0 || $hrs != 0) ? $hrs."h " : "", ($day != 0 || $hrs != 0 || $min != 0) ? $min."m " : "", $sec."s ago" ); return $str; } echo ago(3600);
Output for 4.3.0 - 7.1.0
16150d 5h 30m 43s ago