How to compare DateTime without time via LINQ?

前端 未结 9 621
夕颜
夕颜 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:41

    Try this code

    var today = DateTime.Today;
    var q = db.Games.Where(t => DbFunctions.TruncateTime(t.StartDate) <= today);
    

提交回复
热议问题