System.Globalization.Calendar.GetWeekOfYear Method

Returns the week of the year that includes the date in the specified DateTime value.

Syntax

public virtual int GetWeekOfYear (DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)

Parameters

time
A date and time value.
rule
An enumeration value that defines a calendar week.
firstDayOfWeek
An enumeration value that represents the first day of the week.

Returns

A positive integer that represents the week of the year that includes the date in the time parameter.

Remarks

This method can be used to determine the number of weeks in the year by setting time to the last day of the year.

The System.Globalization.DateTimeFormatInfo object for a particular culture that uses the calendar indicated by the DateTimeFormatInfo.Calendar property includes the following culture-specific values that can be used for the rule and firstDayOfWeek parameters:

The following example uses the current culture's System.Globalization.DateTimeFormatInfo object to determine that January 1, 2011 is in the first week of the year in the Gregorian calendar.

code reference: System.Globalization.Calendar.GetWeekOfYear#2

For some calendars, a call to the Calendar.GetWeekOfYear(DateTime, CalendarWeekRule, DayOfWeek) method throws an ArgumentOutOfRangeException for particular combinations of rule and firstDayOfWeek values even if time is greater than the date returned by that calendar's Calendar.MinSupportedDateTime property. The following table lists the affected calendars, the specific rule values, and the range of the earliest supported time values. The specific minimum DateTime value depends on the value of the firstDayOfWeek parameter.

System.Globalization.ChineseLunisolarCalendar

CalendarWeekRule.FirstFullWeek

2/19/1901 to 2/25/1901

1/1/1901 to 1/7/1901

System.Globalization.ChineseLunisolarCalendar

CalendarWeekRule.FirstFourDayWeek

2/19/1901 to 2/22/1901

1/01/1901 to 1/04/1901

System.Globalization.HebrewCalendar

CalendarWeekRule.FirstDay

9/17/1583

1/01/5344

System.Globalization.HebrewCalendar

CalendarWeekRule.FirstFullWeek

9/17/1583 to 9/23/1583

1/01/5344 to 1/07/5344

System.Globalization.HebrewCalendar

CalendarWeekRule.FirstFourDayWeek

9/17/1583 to 9/20/1583

1/01/5344 to 1/04/5344

System.Globalization.HijriCalendar

CalendarWeekRule.FirstFullWeek

7/18/0622 to 7/24/0622

1/01/0001 to 1/07/0001

System.Globalization.HijriCalendar

CalendarWeekRule.FirstFourDayWeek

7/18/0622 to 7/21/0622

1/01/0001 to 1/04/0001

System.Globalization.JapaneseLunisolarCalendar

CalendarWeekRule.FirstFullWeek

1/28/1960 to 2/03/1960

1/01/35 to 1/07/0035

System.Globalization.JapaneseLunisolarCalendar

CalendarWeekRule.FirstFourDayWeek

1/28/1960 to 1/31/1960

1/01/0035 to 1/04/0035

System.Globalization.JulianCalendar

CalendarWeekRule.FirstFullWeek

1/01/0001 to 1/05/0001

1/03/0001 to 1/07/0001

System.Globalization.JulianCalendar

CalendarWeekRule.FirstFourDayWeek

1/01/0001 to 1/02/0001

1/03/0001 to 1/04/0001

System.Globalization.KoreanLunisolarCalendar

CalendarWeekRule.FirstFullWeek

2/14/0918 to 2/20/0918

1/01/0918 to 1/07/0918

System.Globalization.KoreanLunisolarCalendar

CalendarWeekRule.FirstFourDayWeek

2/14/0918 to 2/17/0918

1/01/0918 to 1/04/0918

System.Globalization.PersianCalendar

CalendarWeekRule.FirstFullWeek

3/21/0622 to 3/27/0622

1/01/0001 to 1/07/0001

System.Globalization.PersianCalendar

CalendarWeekRule.FirstFourDayWeek

3/21/0622 to 3/24/0622

1/01/0001 to 1/04/0001

System.Globalization.TaiwanLunisolarCalendar

CalendarWeekRule.FirstFullWeek

2/18/1912 to 2/24/1912

1/01/0001 to 1/07/0001

System.Globalization.TaiwanLunisolarCalendar

CalendarWeekRule.FirstFourDayWeek

2/18/1912 to 2/21/1912

1/01/0001 to 1/04/0001

System.Globalization.UmAlQuraCalendar

CalendarWeekRule.FirstFullWeek

4/30/1900 to 5/06/1900

1/01/1318 to 1/07/1318

System.Globalization.UmAlQuraCalendar

CalendarWeekRule.FirstFourDayWeek

4/30/1900 to 5/03/1900

1/01/1318 to 1/04/1318

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0