Solved

# Converting seconds to days, hours, minutes and seconds

Posted on 2005-04-24
1,130 Views
Is there a module that I can use to convert seconds to days, hours, minutes and seconds? If I have a number of seconds like 774342, I want to know exactly how many days, hours, minutes and seconds that would equal. If there is, could you please post a snippet to get me started? I haven't used modules at all and find the documentation lacking on most of them.

Thanks!
holein5

0
Question by:David Aldridge

LVL 84

Accepted Solution

\$seconds = 774342;
\$days = int(\$seconds/(24*60*60));
\$seconds -= \$days*24*60*60;
\$hours = int(\$seconds/(60*60));
\$seconds -= \$hours*60*60;
\$minutes = int(\$seconds/60);
\$seconds -= \$minutes*60;
printf "%d:%02d:%02d:%02d\n",\$days,\$hours,\$minutes,\$seconds;
0

LVL 1

Author Comment

Excellent! Thank you Ozo!
0

## Featured Post

### Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …