Asp.Net: Method to get week number (getweekofyear)

This method return the integer weeknumber of a specific date. 

public static int GetWeekNumber(DateTime date)
 // Gets the Calendar instance associated with a CultureInfo.
 CultureInfo myCI = new CultureInfo("nl-NL");
 Calendar myCal = myCI.Calendar;

 // Gets the DTFI properties required by GetWeekOfYear.
 CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
 DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;

 return myCal.GetWeekOfYear(date, myCWR, myFirstDOW);

More info:

Leave a Reply

Your email address will not be published. Required fields are marked *