I am using this method to get a list of week start from my data.
However, at the end of the month a week could be a split between 2 months
however i am having a hard time using my method to check the split weeks in my method to get the months
Method to get list of Months
var monthlist = data.Select(x => new { wkdate = x.WKENDstart }).OrderBy(y => y.wkdate).Select(m => new
{
monthname = m.wkdate.ToString("MMM yyyy", CultureInfo.CreateSpecificCulture("en-US"))
}).Distinct().ToList();
Method to check if its a split week
public static bool isSplitWeek(System.DateTime Enddate, System.DateTime Startdate)
{
bool isSameMonth = (Enddate.Month == Startdate.Month) ? true : false;
return !isSameMonth ? true : false;
}
Im basically trying to use an if where it say x.WKENDstart, that way i get both months if a week starts in one month and ends in another.
After deciding on how i could approach this issue i decided to use a .WHERE clause and a .Union
By doing this i was able to handle normal weeks in one section and split weeks in another and just union them together. The key to the issue was to use the where clause.