title: How to convert a DateTime string to a DateTime in SQL Server
body: <p>I have a DateTime varchar in this format: 2005-08-08T00:00:00+01:00.</p>
  
  <ol>
  <li>Does this format have a name? (it's not ISO8601. Is it RFC3339?)</li>
  <li>How can I convert it to a DateTime using Transact-Sql?</li>
  </ol>
  
  <p><strong>EDIT</strong>
  Here's a summary answer, cobbled together from others input:</p>
  
  <ol>
  <li>It <em>is</em> ISO8601 with a time offset from UTC. If it was UTC it would end with a 'Z' instead of '+01:00'.  <a href="http://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC" rel="noreferrer">wikipedia</a></li>
  <li><p>You can convert it to local time or to utc as follows:</p>
  
  <blockquote>
    <p>DECLARE @d VARCHAR(25) SET @d = '2007-08-08T00:01:00+01:00' SET @d =
    '2007-08-08T00:01:00-01:00' SET @d = '2007-08-08T00:01:00+05:30'</p>
    
    <p>SELECT @d as Input, CONVERT(DATETIME, LEFT(@d, 19), 126) AS LocalDate
    , DATEADD(MINUTE  , -CAST((SUBSTRING(@d, 20, 1) + RIGHT(@d, 2)) AS
    INT)  , DATEADD(HOUR 
           ,-CAST(SUBSTRING(@d, 20, 3) AS INT)
           , CONVERT(DATETIME, LEFT(@d, 19), 126))) as UtcDate WHERE @d LIKE '<strong>_<em>-</strong>-</em>_T__:<strong>:</strong>[+-]<strong>:</strong>'</p>
  </blockquote></li>
  </ol>
  
  <p>Results:</p>
  
  <pre><code>Input                     LocalDate               UtcDate
  ------------------------- ----------------------- -----------------------
  2007-08-08T00:01:00+01:00 2007-08-08 00:01:00.000 2007-08-07 23:01:00.000
  
  2007-08-08T00:01:00-01:00 2007-08-08 00:01:00.000 2007-08-08 01:01:00.000
  
  2007-08-08T00:01:00+05:30 2007-08-08 00:01:00.000 2007-08-07 18:31:00.000
  </code></pre>