Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8455269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:14:36+00:00 2026-06-10T12:14:36+00:00

I have a rather weird problem. I live in denmark and here the first

  • 0

I have a rather weird problem. I live in denmark and here the first week (Week 1) of 2013 starts the 31th of december 2012 and lasts for 7 days – as weeks normally do 🙂

According to .NET however the 30th of december is Week 52, the 31th is Week 53 and the 1st of January is Week 1.

Week 53 lasts for only one day, and Week 1 for 6 days. Clearly this must be wrong (a week consisting of less than 7 days) and certainly is wrong in danish context. Where the 31th of december is Week 1, NOT Week 53.

The following code illustrates the problem (CurrentCulture is “da-DK”)

    static void Main(string[] args)
    {
        //Here I get Monday
        DayOfWeek firstDayOfWeek = DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek;             
        //Here I get FirstFourDayWeek
        CalendarWeekRule weekRule = DateTimeFormatInfo.CurrentInfo.CalendarWeekRule; 

        DateTime date = new DateTime(2012,12,30);

        for (int i = 0; i <= 10; i++)
        {
            DateTime currentDate = date.AddDays(i);
            Console.WriteLine("Date: {0} WeekNumber: {1}",
                currentDate.ToShortDateString(),
                CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(currentDate, weekRule, firstDayOfWeek));
        }
        Console.ReadLine();
    }

Have I done something wrong or is this a bug in .NET ? If the latter – do you have suggestions for calculating weeknumbers correctly ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:14:38+00:00Added an answer on June 10, 2026 at 12:14 pm

    The problem is that the GetWeekOfYear method does not respect ISO 8601, which is what you expect, but it doesn’t.

    Note that while you are using FirstFourDayWeek, the documentation says:

    The first week based on the FirstFourDayWeek value can have four to seven days.

    which is a violation of the ISO 8601 rule that all weeks have to have seven days.

    Also:

    enter image description here


    You can use the following method to obtain the correct week number according to ISO 8601:

    int weekNumber(DateTime fromDate)
    {
        // Get jan 1st of the year
        DateTime startOfYear = fromDate.AddDays(- fromDate.Day + 1).AddMonths(- fromDate.Month +1);
        // Get dec 31st of the year
        DateTime endOfYear = startOfYear.AddYears(1).AddDays(-1);
        // ISO 8601 weeks start with Monday 
        // The first week of a year includes the first Thursday 
        // DayOfWeek returns 0 for sunday up to 6 for saterday
        int[] iso8601Correction = {6,7,8,9,10,4,5};
        int nds = fromDate.Subtract(startOfYear).Days  + iso8601Correction[(int)startOfYear.DayOfWeek];
        int wk = nds / 7;
        switch(wk)
        {
            case 0 : 
                // Return weeknumber of dec 31st of the previous year
                return weekNumber(startOfYear.AddDays(-1));
            case 53 : 
                // If dec 31st falls before thursday it is week 01 of next year
                if (endOfYear.DayOfWeek < DayOfWeek.Thursday)
                    return 1;
                else
                    return wk;
            default : return wk;
        }
    }
    

    Source (there are also plenty other functions out there…)


    So, changing your loop to

    for (int i = 0; i <= 10; i++)
    {
        DateTime currentDate = date.AddDays(i);
        Console.WriteLine("Date: {0} WeekNumber: {1}: CorrectWeekNumber: {2}",
            currentDate.ToShortDateString(),
            CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(currentDate, weekRule, firstDayOfWeek),
            weekNumber(currentDate));
    }
    

    will result in:

    Date: 30.12.2012 WeekNumber: 52: CorrectWeekNumber: 52
    Date: 31.12.2012 WeekNumber: 53: CorrectWeekNumber: 1
    Date: 01.01.2013 WeekNumber: 1: CorrectWeekNumber: 1
    Date: 02.01.2013 WeekNumber: 1: CorrectWeekNumber: 1
    Date: 03.01.2013 WeekNumber: 1: CorrectWeekNumber: 1
    Date: 04.01.2013 WeekNumber: 1: CorrectWeekNumber: 1
    Date: 05.01.2013 WeekNumber: 1: CorrectWeekNumber: 1
    Date: 06.01.2013 WeekNumber: 1: CorrectWeekNumber: 1
    Date: 07.01.2013 WeekNumber: 2: CorrectWeekNumber: 2
    Date: 08.01.2013 WeekNumber: 2: CorrectWeekNumber: 2
    Date: 09.01.2013 WeekNumber: 2: CorrectWeekNumber: 2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a rather weird problem that should fix a bug in my current
I have a rather small but weird problem that I can't seem to fix.
I have run into a rather weird little problem. In the following code I
I have run into a rather weird problem. I have created the following query
I came about a rather weird problem today. I have a math library optimized
I have rather weird problem with paperclip gem. You know it defines Attachment class
I have a rather weird problem deploying my application ... I compile the application
I have a rather weird problem with a control that doesn't want to resize.
I have a weird (and rather frightening) problem with Ajax. I'm returning 3 large
I have a rather weird problem: How do I compare strings (using Python )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.