Tried your idea, which looks like it should work too, but it still is not working. Very strange.
After leaving it for a while I came back looked it over and decided the StartDate has to be subtracted from the DateTime, not the DateTime subtracted from the StartDate... and it works!!
After leaving it for a while I came back looked it over and decided the StartDate has to be subtracted from the DateTime, not the DateTime subtracted from the StartDate... and it works!!
congratulations!Welcome to the forum again next time to share us your nice solutions as well as chat with us about the technology of ASP.NET……!
isEmpty
Member
2 Points
10 Posts
Linq and filter results by dates
Mar 30, 2012 02:45 PM|LINK
This doesn't seem to ever give results great than 0 even though the DateTime.Now falls between the startdate and enddate pulled from an XML file...
"... OrderBy(c => c.StartDate).Where(c => (c.EndDate.Subtract(DateTime.Now).Days > 0 && c.StartDate.Subtract(DateTime.Now).Days > 0)"
Any suggestions?
Thank you,
John
snajp3er
Member
97 Points
26 Posts
Re: Linq and filter results by dates
Mar 30, 2012 02:52 PM|LINK
Becouse you chceck if EndDate and StartDate is grater than 0 :) When DateTime.Now is between dates always one is lower than 0. Change to:
d4daud
Contributor
2293 Points
468 Posts
Re: Linq and filter results by dates
Mar 30, 2012 02:52 PM|LINK
isEmpty
Member
2 Points
10 Posts
Re: Linq and filter results by dates
Mar 30, 2012 06:48 PM|LINK
Tried your idea, which looks like it should work too, but it still is not working. Very strange.
After leaving it for a while I came back looked it over and decided the StartDate has to be subtracted from the DateTime, not the DateTime subtracted from the StartDate... and it works!!
(c.EndDate.Subtract(DateTime.Today).Days > 0 && DateTime.Today.Subtract(c.StartDate).Days > 0)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Linq and filter results by dates
Apr 01, 2012 12:28 AM|LINK
congratulations!Welcome to the forum again next time to share us your nice solutions as well as chat with us about the technology of ASP.NET……!
Reguards!