title: Getting offset of datetimeoffset in SQL Server
body: <p>In SQL Server I need to find the offset of a given <code>datetimeoffset(7)</code>.</p>
  
  <p>I have researched the documentation and there are all ways to change the offset but not a way to know the offset of a particular value (sorry if I missed it).</p>
  
  <p>Well I came up with the following piece of code that I find too complicated although seems to work.</p>
  
  <pre><code>DECLARE @datetimeOffset datetimeoffset(7)
  
  SET @datetimeOffset = CAST('2007-05-08 22:35:29.1234567-05:00' AS datetimeoffset(7))
  
  DECLARE @result datetimeoffset(7)
  DECLARE @offsetMin int
  
  SET @offsetMin = DATEDIFF(mi, cast(SWITCHOFFSET(@datetimeOffset, '+00:00') as datetime), cast(@datetimeOffset as datetime)) 
  
  SELECT @offsetMin
  </code></pre>
  
  <p>I still have to do the conversion to the +00:00 format but wanted to check if there is a better way of doing this.</p>
  
  <p>Thanks!</p>