Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有2个日期时间条件的linq where子句_C#_Linq - Fatal编程技术网

C# 具有2个日期时间条件的linq where子句

C# 具有2个日期时间条件的linq where子句,c#,linq,C#,Linq,我有一个Where子句,如下所示: where p.Appoint.Date > TheStartTime.Date && p.Appoint.Date < TheEndTime.Date 它返回一个计数(但不是我想要的计数)。我做错了什么 谢谢你的建议。在做类似的事情时,使用勾号总是比较容易 这样你就可以比较两个数字了。好的,我知道了: a) use >= and <= b) remove the .Date a)使用>=和您的第一个子句具有唯

我有一个Where子句,如下所示:

where p.Appoint.Date > TheStartTime.Date && p.Appoint.Date < TheEndTime.Date
它返回一个计数(但不是我想要的计数)。我做错了什么


谢谢你的建议。

在做类似的事情时,使用勾号总是比较容易

这样你就可以比较两个数字了。

好的,我知道了:

 a) use >= and <= 
 b) remove the .Date

a)使用>=和您的第一个子句具有唯一的上下限。因此,例如,如果较低的日期是上午8:30,则这将与精确时间为上午8:30的记录不匹配,仅与晚于该时间的记录匹配


你的第二条是寻找一个完全匹配的。如果您想要包含边界,请使用
=
例如日期为
2011-05-12
2011-05-13
。否
。日期将大于第一个,小于第二个。乍一看,将您的比较改为
=
您是否尝试过p.Appoint.Date>=开始时间.日期和&p.Appoint.Date伙计们,您应该将这些作为实际答案发布…好吧,我添加了=现在它给了我超出预期的结果。如果开始时间是2011年5月5日11:00,结束时间是2011年5月6日11:00,则它将返回5月5日和5月6日的所有项目,而不考虑一天中的时间。@frencie,这是因为你告诉它这样做
.Date
有效地降低了时间分量(使其为12 AM),均衡了
5/5/2011 12:00 AM
5/5/2011 11:59:59 PM
。如果时间很重要,不要只比较日期!与
date1
相比,
date1.Ticks
更容易些什么?你更喜欢以12为基数思考?如果你只比较两个日期,就不需要以12为基数思考。是的,我更喜欢考虑实际日期,而不是像634408429027550057这样的数字。
 a) use >= and <= 
 b) remove the .Date