title: Convert datetimeoffset to varchar
body: <p>I've searched everywhere but can't seem to find this info and it's not listed (as far as I can tell) in the MS documentation for <a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver15#date-and-time-styles" rel="nofollow noreferrer">CONVERT</a>.</p>
  <p>Given the Date/Time/Offset: <code>1997-12-31 14:53:00.123 +04:30</code></p>
  <p>It's easy to cast it to <code>datetimeoffset(3)</code> as <code>CONVERT( datetimeoffset(3), '1997-12-31 14:53:00.123 +04:30' )</code></p>
  <p>But converting it from a <code>datetimeoffset(3)</code> back to text isn't as simple.</p>
  <pre><code>DECLARE @DateTimeOffset datetimeoffset(3) = '1997-12-31 14:53:00.123 +04:30';
  DECLARE @StringDTO varchar(255) = CONVERT( nvarchar, @DateTimeOffset, 121 );
  SELECT @StringDTO;
  </code></pre>
  <p>The two closest styles I could find were <code>121</code> and <code>127</code>:</p>
  <ul>
  <li><code>121</code> returns <code>1997-12-31 14:53:00.1230000 +0</code> which is missing the actual TimeZone value</li>
  <li><code>127</code> returns <code>1997-12-31T10:23:00.1230000Z</code> which is converting everything to Zulu time.</li>
  </ul>
  <p>Does anyone know the conversion style for <code>yyyy-mm-dd hh:mi:ss.fff +zz:zz</code> / <code>1997-12-31 14:53:00.123 +04:30</code> please?</p>
  <p>I can easily roll my own function but wanted to confirm there wasn't an existing function already in SQL Server before I did that.</p>
  <p>Much appreciated.</p>