I’ve a source data which contains the data in month as below:
Oct 2011
Nov 2011
Dec 2011
Jan 2012
Feb 2012
I need to select all the months that invoice falls on to. The invoice has properties below:
Invoice.StartDate=13-10-2011;
Invoice.EndDate=11-01-2012;
sourceData.Where(x => x.SourceDate.Month >= Invoice.StartDate.Month &&
x.SourceDate.Year==Invoice.StartDate.Year &&
x.SourceDate.Month <= Invoice.EndDate.Month &&
x.SourceDate.Year == Invoice.EndDate.Year).ToList();
The above query returns 0. I’m expecting the filtered data source result below:
Oct 2011
Nov 2011
Dec 2011
Jan 2012
Could someone help me to achieve above?
This solution simply creates
DateTimes withDayset to 0 so they can be compared directly. It uses query syntax because it’s more convenient for creating the newDateTimes.