title: Error when converting float to datetime
body: <p>I am trying to convert a float in the format yyyymmdd to datetime. According to <a href="http://msdn.microsoft.com/en-us/library/ms187928.aspx" rel="nofollow">this</a> the correct style code for that format is 112.</p>
  
  <p>Code:</p>
  
  <pre><code>select
      convert(datetime,cast(myDate as numeric),112)
  from MyTable
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Msg 8115, Level 16, State 2, Line 1
  Arithmetic overflow error converting expression to data type datetime.
  </code></pre>
  
  <p>I get the same error without the <code>cast as numeric</code> part. I've been looking around for a couple hours, but I haven't been able to find anything that fixes this. If you know a better way to convert the float to a datetime I would be open to that idea.</p>
  
  <p>Thank you for your help.</p>
  
  <p><strong>EDIT</strong><br>
  Here is the working code:</p>
  
  <pre><code>SELECT
      case when isdate(CAST(CAST(myDate AS INT) AS VARCHAR(8))) = 1
              then CAST(CAST(CAST(myDate AS INT) AS VARCHAR(8)) AS DATETIME)
          end
  from MyTable
  </code></pre>
  
  <p>I wrapped it in the <code>isdate</code> because there were a few invalid dates in there. Thanks to Matt for the help.</p>
  
  <p><strong>EDIT2</strong><br>
  Better version:</p>
  
  <pre><code>SELECT
      TRY_CAST(CAST(CAST(myDate AS INT) AS VARCHAR(8)) AS DATETIME)
  FROM MyTable
  </code></pre>