Search code examples
linq-to-nhibernatesmalldatetime

How to compare just the date, not the timestamp using LINQ


I'm trying to compare just the date of a column but because the query below is also comparing the time I get no result set back.

How could I write this same LINQ query if I'm only interested in the actual date value matching?

The column "ImportDate" has a value that looks similar to this 2009-08-30 12:26:00

from t in UnitsOfWork _
where t.ImportDate = "08/30/2009" _
select t

Solution

  • You can compare it as a string or you can use just the Date property on ImportDate

    where t.ImportDate.ToString("yyyyMMdd") == "20090830"
    

    or

    where t.ImportDate.Date == new DateTime(2009,8,30)