比较 LINQ to SQL 中的两个日期

发布于 2024-11-04 14:10:55 字数 284 浏览 5 评论 0原文

我有一个数据库,其中有一个名为会议的表。会议日期使用以下格式存储在此表中:2011 年 5 月 2 日 的格式(例如)为 5/2/2011

我的要求是获取两个日期之间的会议(例如,2011 年 4 月 25 日和 2011 年 5 月 2 日),并编写一个查询来比较日期与这两个日期。是否与 2011 年 4 月 25 日相比 < 2011 年 4 月 26 日?比较是如何进行的?

我正在使用 SQL Server 2008 和 LINQ to SQL 查询。

I have a database with a table named meeting. Meeting dates are stored in this table using the following format: May 2nd 2011 is (for example) formatted as 5/2/2011.

My requirement is to get the meetings between two dates (say, 4/25/2011 and 5/2/2011) and to write a query comparing a date with these two dates. Does it compare like 4/25/2011 < 4/26/2011? How does the comparison take place?

I am using SQL Server 2008 and LINQ to SQL queries.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不咬妳我踢妳 2024-11-11 14:10:55

像这样的东西

DateTime start = new DateTime("4/25/2011");
DateTime end = new DateTime("5/2/2011");
var result = db.Meeting.Where(d => d.MeetingDate >= start 
                 && d.MeetingDate <= end);

Something like this

DateTime start = new DateTime("4/25/2011");
DateTime end = new DateTime("5/2/2011");
var result = db.Meeting.Where(d => d.MeetingDate >= start 
                 && d.MeetingDate <= end);
是伱的 2024-11-11 14:10:55

查询风格:

from m in db.Meetings
where m.Start => start && m.End <= end
select m;

方法风格:

db.Meetings.Where(m => m.Start => start && m.End <= end);

Query style:

from m in db.Meetings
where m.Start => start && m.End <= end
select m;

Method style:

db.Meetings.Where(m => m.Start => start && m.End <= end);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文