Converting seconds to days, hours, minutes and seconds

Posted on 2005-04-24
Last Modified: 2012-05-05
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.


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;
    LVL 1

    Author Comment

    by:David Aldridge
    Excellent! Thank you Ozo!

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    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 …
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now