C# Get Week Number In Year

Problem : How do I get number of week per year.

Solution :

// Get Num Of Week Per Year
 public static int Iso8601WeekNumber(DateTime dt)
{
     System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
     int weekNumOnMonth = ci.Calendar.GetWeekOfYear(dt, ci.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.FirstDayOfWeek);
     return weekNumOnMonth;
}

Reference:
using System.Globalization;

0 comments: