I have to calculate the week number based on a date. This might be easy and I've done in this way (thanks to another SO post):
public static int GetCurrentWeekNumber(DateTime time)
{
DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(time);
if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
{
time = time.AddDays(3);
}
return CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}
The new request is to calculate the week number not from Monday but from thursday to the next wednesday (included). Any hints?