title: SQL to calculate time difference between two different rows and column
body: <p>I have a table in SQL Server 2005 with two fields datetime, one is Start other End.</p>
  
  <p>Example</p>
  
  <pre><code>select Start , End   from   launchings   where id = 210423 order by 1 asc
  </code></pre>
  
  <p>My result is</p>
  
  <pre><code>2013-11-01 08:30:00.000 2013-11-01 12:00:00.000
  2013-11-01 13:00:00.000 2013-11-01 19:00:00.000
  2013-11-01 19:00:00.000 2013-11-01 20:00:00.000
  2013-11-01 19:00:00.000 2013-11-01 20:00:00.000
  
  2013-11-04 08:30:00.000 2013-11-04 12:00:00.000
  2013-11-04 13:00:00.000 2013-11-04 19:30:00.000
  </code></pre>
  
  <p>I need get the first and the last time a day and the interval between them, which would for example lunchtime</p>
  
  <p>Example
       Day 04 - Result that I want</p>
  
  <pre><code>    Day         Start   Start interval   End interval   End
  2013-11-04 -    08:00      12:00             13:00      19:30    
  2013-11-01 -    08:30      12:00             13:00      20:00   
  </code></pre>
  
  <p>Start and End I did. I need Interval </p>
  
  <pre><code>  SELECT 
      convert(char(10), DATEADD(DAY, DATEDIFF(DAY, 0, Inicio), 0),103) AS Day,    
      MIN(convert(char(5),Inicio,108)) AS MinDate,    
      MAX(convert(char(5),Fim,108)) AS MaxDate
  
  from   Lancamentos where matricula = 210423 
  GROUP BY
      DATEADD(DAY, DATEDIFF(DAY, 0, Inicio), 0)
  </code></pre>
  
  <p>Result  </p>
  
  <pre><code>Day         MinDate MaxDate
  01/11/2013  08:30   20:00
  04/11/2013  08:30   19:30
  </code></pre>