What?
This is intended for activity/session durations and although I usually get MySQL to do the date/time calculations, there are times when we have to do with PHP. This is the shortest way I know to properly convert seconds into total hours, minutes and seconds (taking into account regional settings and without using a date function).
How?
copyrawstyler
$total_time =intval(intval($total_seconds)/ 3600).":";
$total_time.=str_pad(intval(($total_seconds/60)%60),2,"0",STR_PAD_LEFT).":";
$total_time.=str_pad(intval($total_seconds%60),2,"0",STR_PAD_LEFT);
// yields
// 82800 = 23:00:00
// 108000 = 30:00:00
- $total_time =intval(intval($total_seconds)/ 3600).":";
- $total_time.=str_pad(intval(($total_seconds/60)%60),2,"0",STR_PAD_LEFT).":";
- $total_time.=str_pad(intval($total_seconds%60),2,"0",STR_PAD_LEFT);
-
On one line:
copyrawstyler
$total_time=intval(intval($total_seconds)/ 3600).":".str_pad(intval(($total_seconds/60)%60),2,"0",STR_PAD_LEFT).":".str_pad(intval($total_seconds%60),2,"0",STR_PAD_LEFT);
- $total_time=intval(intval($total_seconds)/ 3600).":".str_pad(intval(($total_seconds/60)%60),2,"0",STR_PAD_LEFT).":".str_pad(intval($total_seconds%60),2,"0",STR_PAD_LEFT);
Category: Personal Home Page :: Article: 413