我有一种方法可以检查当月有多少预订:
if (item.DateTimeScheduled.Month == DateTime.Now.Month)
本周有可能做类似的事吗?如何查看当周完成的预订次数?
答案 0 :(得分:1)
如果你有一个带有DateTime
属性的“Items”集合,并且你想要计算本周的所有内容,那么这应该有效:
var calendar = DateTimeFormatInfo.CurrentInfo.Calendar;
var weekRule = DateTimeFormatInfo.CurrentInfo.CalendarWeekRule;
var firstDay = DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek;
int week = calendar.GetWeekOfYear(DateTime.Today, weekRule, firstDay);
int thisWeekBookings = items
.Count(i => i.DateTimeScheduled.Year == DateTime.Today.Year &&
week == calendar.GetWeekOfYear(i.DateTimeScheduled, weekRule, firstDay));