.netentity-frameworklinqsqldatetimedbfunctions

DbFunctions or similar to compare time of day of a datetime type column in Linq to Entity Framework


I know there is a function to compare just the date of a datetime type column, but what if I want to only compare the time of it to another time. Is there a function in Linq To Entities?

DbFunctions.TruncateTime(q.EndDate.Value)

Solution

  • I used this and it worked fine.

    SqlFunctions.DatePart("hh", t.Time.Value) == SqlFunctions.DatePart("hh", newTime) && SqlFunctions.DatePart("n", t.Time.Value) == SqlFunctions.DatePart("n", newTime)