You can change all the years to date from the year does not matter, and then you can check it this way.
DateTime twoDaysAgo = DateTime.Today.AddDays(-2); DateTime monthAway = DateTime.Today.AddMonths(1); List<DateTime> checkDates = new List<DateTime> { new DateTime(2011, 11, 3), new DateTime(2011, 12, 5), new DateTime(2011, 12, 6), new DateTime(2011, 11, 2) }; checkDates = checkDates.Select(x => new DateTime(DateTime.Today.Year, x.Month, x.Day)).ToList(); var bdays = from p in checkDates where (p >= twoDaysAgo && p <= monthAway) || (p>= twoDaysAgo.AddYears(-1) && p <= monthAway.AddYears(-1)) orderby p select p;
The result is
11/3/2013 12:00:00 AM 12/5/2013 12:00:00 AM
This also works with the following list of dates when today is a new DateTime(2013, 12, 31)
List<DateTime> checkDates = new List<DateTime> { new DateTime(2011, 12, 29), new DateTime(2011, 12, 28), new DateTime(2011, 1, 30), new DateTime(2011, 2, 2) };
Giving Results
1/30/2013 12:00:00 AM 12/29/2013 12:00:00 AM
Harrison
source share