如何在LINQ比较日期? [英] How to compare dates in LINQ?
本文介绍了如何在LINQ比较日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要检查是否给定的日期是一个多月早于使用LINQ今天的日期。
I want to check if a given date is more than a month earlier than today's date using LINQ.
什么是语法呢?
在此先感谢。
推荐答案
我认为你在where子句中谈到。它基本上是你会在其他地方比较两个datetime对象以相同的方式。
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;
}
这篇关于如何在LINQ比较日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文