whats the simplest way to calculate the Monday in the first week of the year
Try this for a solution without looping:
public DateTime FirstMonday(int year)
{
DateTime firstDay = new DateTime(year, 1, 1);
return new DateTime(year, 1, (8 - (int)firstDay.DayOfWeek) % 7 + 1);
}
private DateTime GetFirstMondayOfYear(int year)
{
DateTime dt = new DateTime(year, 1, 1);
while (dt.DayOfWeek != DayOfWeek.Monday)
{
dt = dt.AddDays(1);
}
return dt;
}