How to compare DateTime without time via LINQ?

前端 未结 9 638
夕颜
夕颜 2020-12-08 18:03

I have

var q = db.Games.Where(t => t.StartDate >= DateTime.Now).OrderBy(d => d.StartDate);

But it compares including time part of

9条回答
  •  不知归路
    2020-12-08 18:45

    DateTime dt=DateTime.Now.date;
    
    var q = db.Games.Where(
        t =>EntityFunction.TruncateTime(t.StartDate.Date >=EntityFunction.TruncateTime(dt)).OrderBy(d => d.StartDate
    );
    

提交回复
热议问题