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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:51:17+00:00 2026-06-15T10:51:17+00:00

The title might be a bit confusing so allow me to explain. I’m using

  • 0

The title might be a bit confusing so allow me to explain. I’m using a table to record my work logs. Every day I’ll create an entry stating from what time to what time I have worked and I’ll add a comment describing what I did.

I then use a query to compare the timestamps to figure out exactly how many hours and minutes I have worked that day. Additionally, I use a query to calculate the sum of hours and minutes I have worked the entire year. That’s where I’m running into a problem. My query is as follows.

SELECT TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(entry_end_time, entry_start_time)))), '%H:%i') 
AS total FROM entry 
WHERE entry_date BETWEEN '2012-01-01' AND '2012-12-31' AND user_id = 3

By default, MySQL TIME fields allow a time range of ‘-838:59:59’ to ‘838:59:59’. I have currently logged more than 900 hours of work this year though, and I want the result of my query to reflect this. Instead, the result is 838:59:59, which makes sense because that is the limit.

Is there any way around this so the result of the query can go beyond 839 hours, or would I have to use something like PHP to go over the entire table and add it all up? I kind of want to avoid that if possible.

  • 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-15T10:51:19+00:00Added an answer on June 15, 2026 at 10:51 am

    I’d just retrieve the total number of seconds worked, and convert to hours/minutes as required in the presentation layer of my application (it is, after all, a simple case of division by 60):

    <?
      $dbh = new PDO("mysql:dbname=$dbname", $username, $password);
      $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
    
      $qry = $dbh->prepare('
        SELECT SUM(TIME_TO_SEC(entry_end_time)-TIME_TO_SEC(entry_start_time))
        FROM   entry 
        WHERE  entry_date BETWEEN :start_date AND :end_date
           AND user_id = :user_id
      ');
    
      $qry->execute([
        ':start_date' => '2012-01-01',
        ':end_date'   => '2012-12-31',
        ':user_id'    => 3
      ]);
    
      list ($totalMins, $remngSecs) = gmp_div_qr($qry->fetchColumn(), 60);
      list ($totalHour, $remngMins) = gmp_div_qr($totalMins, 60);
    
      echo "Worked a total of $totalHour:$remngMins:$remngSecs.";
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the title might be a little bit confusing, let me explain, ;) I have
Title might be a bit confusing, so let me explain. I have a website
The title might have been a bit confusing but I can clarify here. I'm
The title might be a bit confusing, basically I'm trying to write up a
Okay so the title might sound a bit confusing, but here's what I want
The title might not explain my problem fully but I wasn't sure how to
Does that title sound confusing? I thought it might well anyways. When I person
The title might be a bit misleading, but I couldn't figure out a better
The title might be a bit misleading, but I don't know how else to
The title of this question might be a bit off but its the closest

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.