Reputation: 585
I am trying out a linq query check expiry by comparing a saved date and current date in mvc3 controller
[AllowAnonymous]
public ActionResult _leftHomeAd()
{ var LhAd = db.Adverts
.Where(u => u.ACatId ==1)
.Where(u => u.OffDate <= DateTime.Now.Day);
return PartialView(LhAd);
And I get the error that I cannot use <= for system date. Can someone point me in the right direction so that my query can retrieve only adverts that have not expired.
Upvotes: 0
Views: 1161
Reputation: 35477
Why are you using DateTime.Now.Day
? Change it:
.Where(u => u.OffDate <= DateTime.Now);
Upvotes: 0
Reputation: 75306
You should change from
DateTime.Now.Day
to
DateTime.Now.Date
because Day
is int
, not DateTime
Upvotes: 1