DateTime startDate1 = (DateTime)StartDate;
DateTime endDate1 = (DateTime)EndDate;
DayOfWeek? day = db.DayOfWeek;
var dayCount = dates.Count(x => x.DayOfWeek == day);
List<DateTime> dates =
Enumerable.Range(0, (int)((EndDate - StartDate).TotalDays) + 1)
.Select(n => StartDate.AddDays(n))
.ToList();
DateTime startDate1 = new DateTime(2018, 11, 01);
DateTime endDate1 = new DateTime(2018, 11, 30);
DateTime startDate2 = new DateTime(2018, 11, 25);
DateTime endDate2 = new DateTime(2018, 11, 30);
if ((startDate2 >= startDate1 && startDate2 <= endDate1) ||
(endDate2 >= startDate1 && endDate2 <= endDate1))
我要计算startDate1和endDate1范围内的DayOfWeek数,并从该范围中完全排除startDate2和endDate2。
在上面的示例范围中,当我希望当前代码返回“ 3”时,我的当前代码在星期一返回“ 4”。
让我们说endDate1现在是(2018,12,31),其余日期都一样,它应该在星期一返回计数'8'而不是'9'。
基本上,我想从计数中排除(2)范围,无论它是否在(1)范围之内/重叠。我该怎么办?