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

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1150
  • Last Modified:

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.


David Aldridge
David Aldridge
1 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;
David AldridgeAuthor Commented:
Excellent! Thank you Ozo!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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