Here another approach taken from my article
Time Period Library for .NET[
^], which returns addditional the year of the week.
public enum YearWeekType
{
Calendar,
Iso8601,
}
public static class TimeTool
{
public static void GetWeekOfYear( DateTime moment, YearWeekType yearWeekType,
out int year, out int weekOfYear )
{
GetWeekOfYear( moment, Thread.CurrentThread.CurrentCulture, yearWeekType, out year, out weekOfYear );
}
public static void GetWeekOfYear( DateTime moment, CultureInfo culture, YearWeekType yearWeekType,
out int year, out int weekOfYear )
{
GetWeekOfYear( moment, culture, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek, yearWeekType,
out year, out weekOfYear );
}
public static void GetWeekOfYear( DateTime moment, CultureInfo culture,
CalendarWeekRule weekRule, DayOfWeek firstDayOfWeek, YearWeekType yearWeekType, out int year, out int weekOfYear )
{
if ( culture == null )
{
throw new ArgumentNullException( "culture" );
}
if ( yearWeekType == YearWeekType.Iso8601 && weekRule == CalendarWeekRule.FirstFourDayWeek && firstDayOfWeek == DayOfWeek.Monday )
{
DayOfWeek day = culture.Calendar.GetDayOfWeek( moment );
if ( day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday )
{
moment = moment.AddDays( 3 );
}
}
weekOfYear = culture.Calendar.GetWeekOfYear( moment, weekRule, firstDayOfWeek );
year = moment.Year;
if ( weekOfYear >= 52 && moment.Month < 12 )
{
year--;
}
}
}