How to compare dates in LINQ?

后端 未结 3 1490
死守一世寂寞
死守一世寂寞 2020-12-17 14:16

I want to check if a given date is more than a month earlier than today\'s date using LINQ.

What is the syntax for this?

Thanks in advance.

3条回答
  •  無奈伤痛
    2020-12-17 14:59

    Just to add, in LINQ To Entities you have to compare to a variable. Example:

            DateTime lastMonth = DateTime.Today.AddMonths(-1);
            using (var db = new MyEntities())
            {
                var query = from s in db.ViewOrTable
                            orderby s.ColName
                            where (s.StartDate > lastMonth)
                            select s;
    
                _dsResults = query.ToList();
            }
    

提交回复
热议问题