How to compare only Date without Time in DateTime types in Linq to SQL with Entity Framework? How to compare only Date without Time in DateTime types in Linq to SQL with Entity Framework? database database

How to compare only Date without Time in DateTime types in Linq to SQL with Entity Framework?


try using the Date property on the DateTime Object...

if(dtOne.Date == dtTwo.Date)    ....


For a true comparison, you can use:

dateTime1.Date.CompareTo(dateTime2.Date);


This is how I do this in order to work with LINQ.

DateTime date_time_to_compare = DateTime.Now;//Compare only date partscontext.YourObject.FirstOrDefault(r =>                EntityFunctions.TruncateTime(r.date) == EntityFunctions.TruncateTime(date_to_compare));

If you only use dtOne.Date == dtTwo.Date it wont work with LINQ (Error: The specified type member 'Date' is not supported in LINQ to Entities)