Get correct week number in .NET

A nice piece of code submitted by Morgan Johansson for getting the correct week number for your region (in this sample code Sweden ("se-SE"):
public int GetWeekNo(DateTime date) {
System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("se-SE");
System.Globalization.Calendar cal = cult_info.Calendar;
int weekNo = cal.GetWeekOfYear(date, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek);
return weekNo;
}

Related posts:

Comments

comments powered by Disqus