I need to get the date of the first and last day of the week knowing the week number.
I get a start date and an end date, representing the first and last day of a s
private static DateTime FirstDateOfWeek(int year, int weekOfYear)
{
var firstDate = new DateTime(year, 1, 4);
//first thursday of the week defines the first week (https://en.wikipedia.org/wiki/ISO_8601)
//Wiki: the 4th of january is always in the first week
while (firstDate.DayOfWeek != DayOfWeek.Monday)
firstDate = firstDate.AddDays(-1);
return firstDate.AddDays((weekOfYear - 1)*7);
}
Easyer and more efficient solution!