比较LINQ和SQL中的两个日期 [英] Comparing two dates in LINQ to SQL

查看:75
本文介绍了比较LINQ和SQL中的两个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我的要求是在两个日期(例如4/25/2011和5/2/2011)之间召开会议,并编写一个查询,将一个日期与这两个日期进行比较.是否比4/25/2011< 2011/4/26?比较如何进行?

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?

我正在使用SQL Server 2008和LINQ进行SQL查询.

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

推荐答案

类似这样的东西

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);

这篇关于比较LINQ和SQL中的两个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆