title: Comparing Date / DateTime ine Entity SQL Where clause
body: <p>I have a method which accepts an ObjectQuery and adds Where clauses to it depending on whether it receives values for various filter parameters. The method has to return an ObjectQuery. How can i do a basic Date comparison e.g. where dateX &lt; dateY.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>if (myDateFilter != null)
  {
      query = query.Where(
          string.Format(
              "it.ExpireDate &lt; cast('{0}' as System.DateTime)",
              myDateFilter));
  }
  </code></pre>
  
  <p>With myDateFilter having a value of DateTime.Now, this code says: System.Data.SqlClient.SqlException: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.</p>
  
  <p>All the other paramaters are string or integer filters so weren't a problem to implement. Any ideas??</p>