title: SQL How to add two dates in HH:MM:SS format
body: <p>Im trying to compute daily total working hours  from two shift morning and afternoon. The columns for morning shift are TimeIN and BreakOut and afternoon BreakIN and TimeOut but Im not getting the total working hours. </p>
  
  <p>TIA. Any help will be appreciated.</p>
  
  <pre><code>declare @timein datetime ='2014-10-29 07:40:14.000'
  ,@breakout datetime = '2014-10-29 12:05:11.000'
  ,@breakin datetime ='2014-10-29 15:06:14.000'
  ,@timeout datetime ='2014-10-29 19:05:09.000'
  ,@totAM int, @totPM int , @totWorkHrs datetime
  
  set @totAM = DATEDIFF ( second , @timein , @breakout )
  set @totPM = DATEDIFF ( second , @breakin , @timeout )
  set @totWorkHrs = @totAM + @totPM
  
  Result:
  @totAM = 15897
  @totPM = 14335
  @totWorkHrs = 30232
  
  Output:
  08:39:xx
  </code></pre>