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
Tim Schmelter's method didn't work for Swedish (sv-SE) culture where weeks start on Mondays. This has been tested with en-US and sv-SE.
public static DateTime GetFirstDateOfWeek(int year, int weekOfYear, CultureInfo cultureInfo)
{
DateTime jan1 = new DateTime(year, 1, 1);
int daysOffset = (int)cultureInfo.DateTimeFormat.FirstDayOfWeek - (int)jan1.DayOfWeek;
DateTime firstWeekDay = jan1.AddDays(daysOffset);
int firstWeek = cultureInfo.Calendar.GetWeekOfYear(jan1, cultureInfo.DateTimeFormat.CalendarWeekRule, cultureInfo.DateTimeFormat.FirstDayOfWeek);
if (firstWeek == 1)
{
weekOfYear -= 1;
}
return firstWeekDay.AddDays(weekOfYear * 7);
}