Hi there guys, today I’m going to give you a little snippet that I found on the web which I find very useful and I thought I should share it with you.This function will require 1 parameter, the number of the seconds you want to transform into Days, Hours, Minutes, Seconds.
e.g: 600000 = 6 days, 22 hours, 40 minutes, 0 seconds
1 2 3 4 5 6 7 8 9 10 11 12 | <?php function secsToStr($secs) { $r = NULL; if($secs>=86400){$days=floor($secs/86400);$secs=$secs%86400;$r=$days.' day';if($days<>1){$r.='s';}if($secs>0){$r.=', ';}} if($secs>=3600){$hours=floor($secs/3600);$secs=$secs%3600;$r.=$hours.' hour';if($hours<>1){$r.='s';}if($secs>0){$r.=', ';}} if($secs>=60){$minutes=floor($secs/60);$secs=$secs%60;$r.=$minutes.' minute';if($minutes<>1){$r.='s';}if($secs>=0){$r.=', ';}} $r.=$secs.' second';if($secs<>1){$r.='s';} return $r; } echo secsToStr(600000); ?> |
Hope you find it useful, I sure did !