title: Checking database with date part only on ASP.NET MVC using Entity Framework
body: <p>I am developing an ASP.NET MVC application. I am stuck by a situation and can't move forward. I will explain my scenario. </p>
  
  <p>I have a date column in my database. I'm using a code-first approach. Now when someone adds a new date using <code>DateTime.Now</code> I want to check the database to count how many rows of data are added with today's date. If it's 5 I want to show an error message to the user who is trying to add new data today. But I can't check today's data as datetime always give result with time.</p>
  
  <p>My date model property is </p>
  
  <pre><code> public DateTime? Date { get; set; }
  </code></pre>
  
  <p>Current to code achieve the above is </p>
  
  <pre><code>DateTime date2 = DateTime.Now;
  
  var dateresult = dbcontext.Appointments.Where(q =&gt; q.Date == date2).Count();
  
  if (ModelState.IsValid &amp;&amp; result == 0 &amp;&amp; dateresult &lt;= 5)
  {}
  </code></pre>
  
  <p>but the count doesn't return the result. It is always zero. </p>
  
  <p>Can someone tell me how to achieve this? How to get today's data without comparing time part? I have searched many but couldn't find a suitable answer.</p>