How to compare dates in LINQ?

后端 未结 3 1492
死守一世寂寞
死守一世寂寞 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 15:18

    I assume that you're talking about in the where clause. It's basically the same way you would compare two DateTime objects elsewhere.

    using (DataContext context = new DataContext()) {
       var query = from t in context.table
                   where t.CreateDate.Date < DateTime.Today.AddMonths(-1)
                   select t;
    }
    

提交回复
热议问题