Reputation: 3253
Date_Of_Event.Date <= DateTime.Today.Date.AddDays(-1))
Upvotes: 1
Views: 804
Reputation: 49544
You have the comparison backwards
// This should work in LINQ-to-SQL / EntityFramework
Date_Of_Event >= DateTime.Today.AddDays(-1)
&&
Date_Of_Event < DateTime.Today
or
// This will work in LINQ-to-Objects or anywhere else, really.
Date_Of_Event.Date == DateTime.Today.AddDays(-1)
As a side note, it may be a good idea to store the value of DateTime.Today
in a variable, so that weird bugs don't show up around midnight (or 11:00pm or 1:00am depending on daylight saving time).
Upvotes: 5
Reputation: 60694
Date_Of_Event.Date == DateTime.Today.AddDays(-1)
This will remove the time part of the date time, and keep only the date so you can check for equality instead of the time being inside the correct interval.
Upvotes: 3