linq where clause with 2 datetime conditions
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 <
.
精彩评论