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 8733783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:43:16+00:00 2026-06-13T09:43:16+00:00

Hello i’m going print sum of time from my sql but i could not

  • 0

Hello i’m going print sum of time from my sql but i could not please help me.

$SQL = "SELECT duration FROM core_network ";
$result = mysql_query($SQL);


$c_count='0';
$n="0";
$duration=array();
while ($db_field = mysql_fetch_array($result)) {
$duration[$n]= $db_field['duration'];
 echo $duration[$n];
$n++;
$c_count++;
 }





the result is 18:00:0000:39:0008:00:00


than i found the code from internet


function sum_the_time($Duration) {
 $times = array('18:00:00','00:39:00','08:00:00');
 $seconds = 0;
 foreach ($times as $time)
 {
   list($hour,$minute,$second) = explode(':', $time);
   $seconds += $hour*3600;
   $seconds += $minute*60;
   $seconds += $second;
 }
 $hours = floor($seconds/3600);
 $seconds -= $hours*3600;
 $minutes  = floor($seconds/60);
 $seconds -= $minutes*60;
  // return "{$hours}:{$minutes}:{$seconds}";
 return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
  }
 echo sum_the_time($duration);

how to enter $duration[$n] to $times = array(’18:00:00′,’00:39:00′,’08:00:00′); insteed of times

  • 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-13T09:43:16+00:00Added an answer on June 13, 2026 at 9:43 am

    just pass $duration as argument to the function:

    function sum_the_time($times) {
     $seconds = 0;
     foreach ($times as $time)
     {
       list($hour,$minute,$second) = explode(':', $time);
       $seconds += $hour*3600;
       $seconds += $minute*60;
       $seconds += $second;
     }
     $hours = floor($seconds/3600);
     $seconds -= $hours*3600;
     $minutes  = floor($seconds/60);
     $seconds -= $minutes*60;
      // return "{$hours}:{$minutes}:{$seconds}";
     return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
      }
     echo sum_the_time($duration);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello! I've been programming for a long time but just started developing for android,
Hello and thank you for taking the time to help me solve my problem.
Hello everyone how can I get two values from different select boxes? I get
Hello guys I am seeking help when it comes to getting text from an
Hello I have problem that I'm loosing $_POST['id'] value from select tag after clicking
Hello all I am working on html and javascript.And I am going to ask
Hello i want to make animation of a frame change. But i don't find
Hello I was wondering how I can setup several things in a constructor, but
Hello I need some help with a bug in Internet Explorer 9. I am
hello creating a custom object may be a widely published topic, but my lack

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.