title: How to get the difference between two times with SQL Server?
body: <p>I have the following two column with Time values</p>
  
  <pre><code>;WITH cte AS (
  SELECT *
  FROM (VALUES
  ('08:00:00','18:30:00'),
  ('20:00:00','08:00:00'),
  ('18:30:00','06:00:00'),
  ('08:00:00','18:30:00')) as t(time1, time2)
  )
  </code></pre>
  
  <p>How can I get the following difference values:</p>
  
  <pre><code>result
   10.5
    12
   11.5
   10.5
  </code></pre>
  
  <p>I tried with DATEDIFF but I am never able to get a true values especially for the case from 18:30 to 6:00
  I tried like this, but does not work for this case(8:30 to 6:00) ...</p>
  
  <pre><code>CASE
    WHEN GirisSaati &gt; CikisSaati THEN cast( DATEDIFF(MINUTE, cast(CikisSaati as time ), cast(GirisSaati as time ))as float) / 60  
    WHEN GirisSaati &lt;= CikisSaati THEN  cast( DATEDIFF(MINUTE,cast( GirisSaati as time ), cast(CikisSaati as time ) )as float) /60  
  END
  </code></pre>
  
  <p>Hope to find help, thanks ...</p>