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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:07:49+00:00 2026-06-11T08:07:49+00:00

i have a Mysql table shift_def in the following format. +——————————————————————————-+ | id |

  • 0

i have a Mysql table shift_def in the following format.

+-------------------------------------------------------------------------------+
|  id   |   name   |   start_time   |    end_time   |   description   |  break  |
|-------------------------------------------------------------------------------|
|  101  | Shift1   |    01:03:55    |    06:00:55   |  Shift 1        |   1     |
|-------------------------------------------------------------------------------|
|  102  | Shift2   |    06:03:55    |    01:00:55   |  Shift 2        |   3     |
+-------------------------------------------------------------------------------+

to find the total shift duration. i perform the following process in my php.

$shift_time = mysql_query("select start_time, end_time from rpt_shift_def where name ='Shif1'")or die(mysql_error());
        while ($row = mysql_fetch_assoc($shift_time)) 
        {
           $Total_shift_time = strtotime($row['end_time']) - strtotime($row['start_time']);
            $hours=floor($Total_shift_time/3600);
            $Total_shift_time-=$hours*3600;
            $minutes=floor($Total_shift_time/60);
            $Total_shift_time-=$minutes*60;
            $seconds=$Total_shift_time;
            $Total_shift_time=$hours.":".$minutes.":".$seconds;*/                                                                                                                                                                                                                                                                                                                                                                            
            echo "$Total_shift_time";
            echo "</br>";
        }

the output is

4:57:0

when i try the same for shift 2 the expected output is

18:57:0

but the output is

-6:57:0

the negative value is because end_time of the shift 2 is less than start_time.
how to solve this problem.

can anyone help me out.

  • 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-11T08:07:51+00:00Added an answer on June 11, 2026 at 8:07 am

    If end time is less than start time, add 24 hours (the reason being that the shift ended on the following day).

    Since you have already calculated $Total_shift_time, you can just check if that is negative.

    if( $Total_shift_time < 0 ) {
        $Total_shift_time += 86400;  // Number of seconds in a day
    }
    

    Err… Make sure you do this after you first calculate the shift time and before you start calculating hours, minutes and seconds…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql log table of machine in the following format. --------------------------------------------------------------------------------------------------- |
I have a MySQL table (table1) with following fields... id, title, description, detail, category,
I have the following MySQL table products : id, code, name, color 1, 'D555',
I have MySQL InnoDB table utf-8 encoded. This table has only id and name
I have a mysql table structure like that: id int primary key name varchar
Using MySQL 5 I have a table like this: date (varchar) door (varchar) shift
i have MySql Table name 'category', in that table i have id catname parent_id
I have mysql table 'files'. which contains following order. 1. id 2.filename 3.keywords When
I have MySQL table with the following structure: +---------+--------------+------+-----+---------+----------------+ | Field | Type |
I have created a mysql table with the following columns... item_price, discount, delivery_charge, grand_total

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.