title: SqlDbType.Date SQL Server 2005
body: <p>I have a property like this:</p>
  
  <pre><code>private SqlParameter DateOfBirthSqlParameter
  {
      get
      {
          return new SqlParameter("@date", SqlDbType.Date)
              {
                  Value = dateOfBirth.ToString("MM/dd/yyyy");
              };
      }
  }
  </code></pre>
  
  <p><code>dateOfBirth</code> is a <code>DataTime</code> C# type. I use this parameter to add to my SQL command, that look like this.</p>
  
  <pre><code>Select * From mytable Where dob_dt = @date
  </code></pre>
  
  <p>The problem is that doesn't work in SQL Server 2005. I got an exception: </p>
  
  <blockquote>
    <p><em>System.ArgumentException: The version of SQL Server in use does not
    support datatype 'date'</em></p>
  </blockquote>
  
  <p>This because SQL Server 2005 doesn't support <code>Date</code>, this is a feature of later version (SQL Server <strong>2008</strong>). </p>
  
  <p>There are many solutions to this, for instance change <code>SqlDbType.Date</code> to <code>SqlDbType.DateTime</code></p>
  
  <p>I guess the reference <code>System.Data</code> is a version that provide all features supported for SQL Server 2008. Should I change it to something that only support 2005? that will help to discover other possible mismatches? What is the best way to handle this situation?</p>
  
  <p>Thanks.</p>
  
  <p><strong>Update: 8/31/2012</strong></p>
  
  <p>In the example, I used date of birth but In my application I used something else such as purchase_dt or something like it (with the time on it). My first Select Statement was:</p>
  
  <pre><code>Select * From mytable Where Cast(purchase_dt as Date) = @date
  </code></pre>
  
  <p>and that was fine in my computer with SQL Server <strong>2008</strong> and in another PC with SQL Server <strong>2005</strong> also was fine and just throws an exception when it got to the select. </p>
  
  <p>But, once I fixed that, with:</p>
  
  <pre><code>Select * From mytable Where Cast(DATEDIFF(dd, 0, purchase_dt) as DateTime) = @date
  </code></pre>
  
  <p>This broke the entire web application (in the other PC)... The problem was <code>SqlDbType.Date</code>. but Why it didn't break it before?</p>