Q:

Compare dates linq c#

I cant seem to get my query to check the database if a date exists. Please help.
 DateTime value = new DateTime(2018, 10, 26);
 item = await table.Where(todoItem => todoItem.Date == value.date)
                   .ToListAsync();

I think the format which c# writes their dates and SQL are different so it cant find a match. Also the database is correctly linked to the app as I am able to query other rows in the same table.

A:

As said before, this is likely due to the fact that your DateTime column in the database includes time information.
Rewrite your query like this:
DateTime value = new DateTime(2018, 10, 26);
item = await table.Where(todoItem => todoItem.Date >= value &&
                                     todoItem.Date < value.AddDays(1))
                   .ToListAsync();

This will retrieve all records that fall within the specified range (that is, dates that match the given day, and the DBMS will be able to use indexes that might be defined on the date-column.

