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: 12/1/2016 8:32:55 PM
  • Language: C#
  • Type: string
  • Views: 320

Double click on the code to select all.

 

;