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

  • Home
  • SEARCH
  • 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 3316640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:29:36+00:00 2026-05-17T22:29:36+00:00

I just want to output as a result of a script to be executed

  • 0

I just want to output as a result of a script to be executed through CLI the time the execution of the script took.

for doing that, I set a var at the start of the script

$start_time = time();

and then at the end

date('H:i:s',time() - $start_time);

the problem is that even when the ellapsed time might be in the range of seconds or minutes, it always print that at least an hour has passed:

>>> echo date('H:i:s',1);
01:00:01
>>> echo date('H:i:s', 10);
01:00:10
>>> echo date('H:i:s',3599);
01:59:59
>>> echo date('H:i:s',3600);
02:00:00

shouldn’t it display 00:XX:YY, when less than an hour has passed?
is there something I’m missing, is there a bug?

thanks for your help!

  • 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-05-17T22:29:37+00:00Added an answer on May 17, 2026 at 10:29 pm

    Don’t use date(). When you have time() - $start_time the result is in seconds. Multiply this up if you want it in mintues etc. or use the following function to convert the seconds to Hours, Minutes and Seconds.

    <?php /**
     *
     * @convert seconds to hours minutes and seconds
     *
     * @param int $seconds The number of seconds
     *
     * @return string
     *
     */
    function secondsToWords($seconds) {
        /*** return value ***/
        $ret = "";
    
        /*** get the hours ***/
        $hours = intval(intval($seconds) / 3600);
        if($hours > 0)
        {
            $ret .= "$hours hours ";
        }
        /*** get the minutes ***/
        $minutes = bcmod((intval($seconds) / 60),60);
        if($hours > 0 || $minutes > 0)
        {
            $ret .= "$minutes minutes ";
        }
    
        /*** get the seconds ***/
        $seconds = bcmod(intval($seconds),60);
        $ret .= "$seconds seconds";
    
        return $ret;
    } ?>
    

    Example usage:

    <?php
        /*** time since EPOCH ***/
        echo secondsToWords(time());
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to output current and I wrote import java.util.*; at beginning, and
I want to get output like 0 1 , but the code below just
I have a script that compiles few programs and puts the output into a
I have a jquery script that accesses a db and returns a numeric result
I have a PHP script which I want to output some text which I'm
I'm trying to run a script and output the result in the console. It
I'm working on a script that has gotten so complex I want to include
I want to use DBMS_OUTPUT.PUT_LINE , but the number of rows exceeds just 1.
Just want to ask if i can use Custom Validator in client side without
Just want to make sure one thing. In a windows machine (either a desktop

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.