How to find the duration of two time interval in php?
<p>i have a Mysql table shift_def in the following format.</p>

<pre><code>+-------------------------------------------------------------------------------+
|  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     |
+-------------------------------------------------------------------------------+
</code></pre>

<p>to find the total shift duration. i perform the following process in my php.</p>

<pre><code>$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 "&lt;/br&gt;";
        }
</code></pre>

<p>the output is </p>

<pre><code>4:57:0
</code></pre>

<p>when i try the same for shift 2 the expected output is</p>

<pre><code>18:57:0
</code></pre>

<p>but the output is</p>

<pre><code>-6:57:0
</code></pre>

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

<p>can anyone help me out.</p>
