In my C # program, I ran into an obstacle where I have a table that stores date ranges (columns are the date range identifier (int), start date (DateTime) and end date (DateTime). I want to query the table and to return strings that belong only to a specific date range.I cannot use datetime.date, since this includes the year.
So, for example, I want to query a table and get all date ranges that are between 01-01 and 5-31.
I tried using the following lambda to query a table, but my result set is empty.
List<DateRanges> tempDateRangeList = dataContext .DateRanges .Where(r=>r.BeginDate.Month <= startDate.Month && r.EndDate.Month >= finishDate.Month) .ToList(); tempDateRangeList = tempDateRangeList.Where(r=>r.BeginDate.Day <= startDate.Day && r.EndDate.Day >= finishDate.Day) .ToList();
Does anyone have any suggestions on how I can do this?
Edit:
Examples of BeginDate and EndDate are lists such as:
BeginDate 1/1/2016, 5/25/2016, 9/11/2016
EndDates 05/24/2016, 10/10/2016, 12/31/2016
Filter Date: startDate = 12/8 finishDate = 12/12
Expected Result: Start September 9 End Date 12/31
source share