WeekOfYearISO8601

        public static int WeekOfYearISO8601(this DateTime date)
        {
            var day = (int)CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(date);
            var week = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date.AddDays(4 - (day == 0 ? 7 : day)), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);

            return week;
        }
Example:
int weekNumber = DateTime.Now.WeekOfYearISO8601();

Description

Gets the number of the week according to the definition of the ISO 8601

Details

  • Author: João Mata
  • Submitted on: 1-12-2016 20:32:55
  • Language: C#
  • Type: string
  • Views: 1564

Double click on the code to select all.

 

;