/ Published in: PHP
Use by sending a unix timestamp to countTime(timestamp). It will return something like 40 seconds , 2 weeks, 1 hour. Then just format to your needs like we do in our app: Someone was here 10 minutes ago.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function countTime($given) { $passed=$current-$given; if($given=='') { $passed=100000000000; } $months=$passed/2628000; $weeks=$passed/604800; $days=$passed/86400; $hours=$passed/3600; $minutes=$passed/60; if($passed>(2628000*12)) { $r='Long time'; } elseif($months>=1) { $r=$months." month"; if($months>1) { $r=$r.'s'; } } elseif($weeks>=1) { $r=$weeks." week"; if($weeks>1) { $r=$r.'s'; } } elseif($days>=1) { $r=$days." day"; if($days>1) { $r=$r.'s'; } } elseif($hours>=1) { $r=$hours." hour"; if($hours>1) { $r=$r.'s'; } } elseif($minutes>=1) { $r=$minutes." minute"; if($minutes>1) { $r=$r.'s'; } } else { $r=$passed." second"; if($passed>1) { $r=$r.'s'; } } return $r; }