title: Compare DateTime to string in LINQ query
body: <p>I have a LINQ query which filters some data by comparing it to a given <code>string</code>. My entity has a <code>DateTime</code> field, which I also need to compare to said <code>string</code>.</p>
  
  <p>However, I need the <code>DateTime</code> to be formatted as <code>dd/MM/yyyy</code> but <code>DateTime.ToString()</code> gives <code>m/d/yyyy</code>.</p>
  
  <p>When I try parsing the <code>DateTime</code> with my formatting, I get the following exceptions:</p>
  
  <blockquote>
    <p>An exception of type 'System.NotSupportedException' occurred in
    Project1.dll but was not handled in user code
        LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated
    into a store expression.</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>auditLogs = auditLogs
                  .Where(x =&gt; x.Username.Contains(searchValue) ||
                      x.Description.Contains(searchValue) ||
                      x.EntityType.Contains(searchValue) ||
                      x.EntityState.Contains(searchValue) ||
                      x.ChangeTime.ToString("dd/MM/yyyy").Contains(searchValue));
  </code></pre>
  
  <p>Is there any workaround to this? Or a "proper" way? I know I could just bruteforce it in a loop, but I want to do it elegantly.</p>
  
  <p><strong>EDIT:</strong> I cannot parse the string to DateTime, because the string may be just <code>03/2019</code> or <code>22/02</code> and not a full date.</p>