RE: [PHP] convert seconds to hours, minutes, seconds
Hi Chinmoy, I have a value 178607, which is stored as seconds. I like to convert it (178607 Secs) to Hours, Minutes and Seconds appropiatly. Can anybody help me supplying the code? Try something like this: ?php function sec2hms ($secs) { $hms = ; $hours = intval(intval($secs) / 3600); $hms .= $hours. :; $minutes = intval(($secs / 60) % 60); $hms .= str_pad($minutes, 2, 0, STR_PAD_LEFT). :; $seconds = intval($secs % 60); $hms .= str_pad($seconds, 2, 0, STR_PAD_LEFT); return $hms; } echo sec2hms(6). br; echo sec2hms(60). br; echo sec2hms(66). br; echo sec2hms(3600). br; echo sec2hms(3666). br; echo sec2hms(178607); ? HTH Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert seconds to hours, minutes, seconds
function secondstohours($seconds) { /* [EMAIL PROTECTED] */ $sec=$seconds%3600; return (($seconds-$sec)/3600).':'.($sec/60).':'.($sec%60); } echo secondstohours(7500); Op dinsdag 03 juni 2003 14:38, schreef u: Hello everybody, I have a value 178607, which is stored as seconds. I like to convert it (178607 Secs) to Hours, Minutes and Seconds appropiatly. Can anybody help me supplying the code? Thank You, - Chinmoy __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert seconds to hours, minutes, seconds
I have a value 178607, which is stored as seconds. I like to convert it (178607 Secs) to Hours, Minutes and Seconds appropiatly. Can anybody help me supplying the code? If it's stored in MySQL, you can use SEC_TO_TIME() mysql select sec_to_time(178607); +-+ | sec_to_time(178607) | +-+ | 49:36:47| +-+ 1 row in set (0.00 sec) mysql select sec_to_time(178607)+0; +---+ | sec_to_time(178607)+0 | +---+ |493647 | +---+ 1 row in set (0.00 sec) ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php