Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9247029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:37:54+00:00 2026-06-18T09:37:54+00:00

I would like some help converting seconds into a MM:DD:HH:MM:SS format. I have this

  • 0

I would like some help converting seconds into a MM:DD:HH:MM:SS format.

I have this code here:

<?php
    // Convert seconds into months, days, hours, minutes, and seconds.
    function secondsToTime($ss) {
    $s = $ss%60;
    $m = floor(($ss%3600)/60);
    $h = floor(($ss%86400)/3600);
    $d = floor(($ss%2592000)/86400);
    $M = floor($ss/2592000);

    return "$M months, $d days, $h hours, $m minutes, $s seconds";
    }
?>

It outputs an example of

0 months, 1 days, 3 hours, 46 minutes, 39 seconds

I would just like it to be something like

00:01:03:46:39

How can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:37:56+00:00Added an answer on June 18, 2026 at 9:37 am

    From what I gather, it looks like you’re interested in returning a string with values containing two digits separaed by colons. Assuming the positioning doesn’t need to change, you can do something similar to the following:

    <?php
    // Prefix single-digit values with a zero.
    function ensure2Digit($number) {
        if($number < 10) {
            $number = '0' . $number;
        }
        return $number;
    }
    
    // Convert seconds into months, days, hours, minutes, and seconds.
    function secondsToTime($ss) {
        $s = ensure2Digit($ss%60);
        $m = ensure2Digit(floor(($ss%3600)/60));
        $h = ensure2Digit(floor(($ss%86400)/3600));
        $d = ensure2Digit(floor(($ss%2592000)/86400));
        $M = ensure2Digit(floor($ss/2592000));
    
        return "$M:$d:$h:$m:$s";
    }
    

    Or if you don’t like the thought of having one more function to manage, perhaps this may suit you better:

    <?php
    // Convert seconds into months, days, hours, minutes, and seconds.
    function secondsToTime($ss) {
        $s = $ss%60;
        $m = floor(($ss%3600)/60);
        $h = floor(($ss%86400)/3600);
        $d = floor(($ss%2592000)/86400);
        $M = floor($ss/2592000);
    
        // Ensure all values are 2 digits, prepending zero if necessary.
        $s = $s < 10 ? '0' . $s : $s;
        $m = $m < 10 ? '0' . $m : $m;
        $h = $h < 10 ? '0' . $h : $h;
        $d = $d < 10 ? '0' . $d : $d;
        $M = $M < 10 ? '0' . $M : $M;
    
        return "$M:$d:$h:$m:$s";
    }
    

    And then to call our function (whichever method you decide to use):

    <?php
    
    $ss = 123456;
    print secondsToTime($ss);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help figuring out how I should do this. I would like
I would like some help in converting a string to an array and performing
I am converting some of my java code to scala and I would like
I would like some help about an Android Application. I used the new Google
I would like some help parsing a dynamic (folder.subfolders) xml with xslt, I tried
I am trying to write a query and would like some help if possible.
I'm new to the site. would like some help if at all possible. I
I would like to as some help. Is there a certain method in javascript/jquery
Good morning! I would like to ask some help from you guys on how
I'm still fairly new to mysql and would like to ask for some help.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.