title: How do I calculate interval between two datetime2 columns (SQL Server)?
body: <p>Hi I'm trying to calculate the difference between two columns of datetime2 type.</p>
  
  <p>However SQL server (2012) doesn't seem to like the following:</p>
  
  <pre><code>select cast ('2001-01-05 12:35:15.56786' as datetime2)
      - cast ('2001-01-01 23:45:21.12347' as datetime2);
  
  Msg 8117, Level 16, State 1, Line 2
  Operand data type datetime2 is invalid for subtract operator.
  </code></pre>
  
  <p>Now it works if I cast it to a datetime type:</p>
  
  <pre><code>select cast (cast ('2001-01-05 12:35:15.56786' as datetime2) as datetime) 
      - cast (cast ('2001-01-01 23:45:21.12348' as datetime2) as datetime);
  
  1900-01-04 12:49:54.443
  </code></pre>
  
  <p>However, I am losing precision when I cast it to datetime (note the 3 decimal precision above). In this case, I actually need all 5 decimal points. Is there a way to get the interval between two datetime2 columns and still maintain 5 decimal points of precision? Thanks.</p>