Use Linq query to compare date only with DateTime field

后端 未结 7 1341
孤城傲影
孤城傲影 2020-12-20 14:59

I need to compare just the date only in a Linq query that involves a datetime field. However, the syntax below results in the following error message

<

7条回答
  •  情深已故
    2020-12-20 15:33

    This is how I ended by doing a similar Date search which I had to consider time (Hour and Minutes portion) also

    from x in _db.AgentProductTraining
                    where 
                           x.CreatedOn.Year == mydacourse.DateTakente.Year
                        && x.CreatedOn.Month == course.DateTaken.Month
                        && x.CreatedOn.Day == course.DateTaken.Day
                        && x.CreatedOn.Hour == course.DateTaken.Hour
                        && x.CreatedOn.Minute == course.DateTaken.Minute
                    select x;
    

提交回复
热议问题