Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1150

# Converting seconds to days, hours, minutes and seconds

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
David Aldridge
1 Solution

Commented:
\$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

Author Commented:
Excellent! Thank you Ozo!
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.