16 December 2010

Get the culture specific weeknumber in .NET

The easiest way to get a culture specific weeknumber is the following:
culture.Calendar.GetWeekOfYear(inputDate, 
    culture.DateTimeFormat.CalendarWeekRule, 
    culture.DateTimeFormat.FirstDayOfWeek);

Where culture is the culture you wish to use for determining the weeknumber. To use the current culture, you can use the following:
CultureInfo culture = CultureInfo.CurrentCulture;

No comments :