title: SQL Server - CONVERT varchar to datetime. YYYY-MM-DD 10:30:36.157 format
body: <p>I'm getting the following error when trying to convert a varchar to datetime in sql server.</p>
  
  <p><strong>The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.</strong></p>
  
  <p>Here are the ResponseDate column values:</p>
  
  <pre><code>2012-06-19 10:30:36.157
  2012-06-19 10:30:36.157
  2012-07-09 11:37:14.287
  2012-06-21 10:15:06.733
  2012-07-02 13:19:13.080
  </code></pre>
  
  <p>I'm trying to write a query that selects * in july.</p>
  
  <pre><code>  Select * From table WHERE CONVERT(datetime,ResponseDate)  BETWEEN '20120631' AND '20120801'
  </code></pre>
  
  <p>I thought there wouldnt be any issues because the varchar is already in datetime format. </p>
  
  <p>Can anyone give me advice? Thanks!</p>