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:
http://msdn.microsoft.com/en-us/library/system.globalization.calendar.getweekofyear.aspx

Leave a Reply

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