开发者

linq where clause with 2 datetime conditions

开发者 https://www.devze.com 2023-03-05 07:09 出处:网络
I have a Where clause that looks like this: where p.Appoint.Date > TheStartTime.Date && p.Appoint.Date < TheEndTime.Date

I have a Where clause that looks like this:

where p.Appoint.Date > TheStartTime.Date && p.Appoint.Date < TheEndTime.Date

For some reason, it's returning 0. However, if I write this

where p.Appoint.Date == TheStartTime.Date

it returns a count (not the one I want though). What am I doing wron开发者_运维技巧g?

Thanks for your suggestions.


When doing things like this it's always easier to use Ticks

that way you're comparing between two numbers.


ok, I got it:

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


Your first clause has exclusive upper and lower bounds. So for example if your lower date is 8:30 AM, this will not match records with an exact time of 8:30 AM, only those later than that.

Your second clause is looking for an exact match. If you want inclusive bounds, go with >= and <= instead of > and <.

0

精彩评论

暂无评论...
验证码 换一张
取 消