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

  • SEARCH
  • Home
  • 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 3854032
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:33:40+00:00 2026-05-19T17:33:40+00:00

Is there a pythonic way of getting the equivalent of the following in .NET?

  • 0

Is there a pythonic way of getting the equivalent of the following in .NET?

CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(dt.Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday)

dt.isocalendar()[1] does not seem to work for me as it returns 53 (expecting 52) for datetime.date(2010, 1, 1)

Thanks.

  • 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-05-19T17:33:41+00:00Added an answer on May 19, 2026 at 5:33 pm

    The ISO calendar has a range of confusing rules that are likely the source of the issues you face here. In particular, the .NET implementation of GetWeekOfYear (with the parameters you have used) is so similar to ISO that explicit clarifications are required and linked from MSDN. The result is that isocalendar and GetWeekOfYear will produce results that differ [my emphasis]:

    Specifically ISO 8601 always has 7 day weeks. If the first partial week of a year doesn’t contain Thursday, then it is counted as the last week of the previous year. Likewise, if the last week of the previous year doesn’t contain Thursday then its treated like the first week of the next year. GetWeekOfYear() has the first behavior, but not the second.

    Some suggestions for correcting GetWeekOfYear are discussed at the link above and also at Is .NET giving me the wrong week number for Dec. 29th 2008? If you actually want to match the GetWeekOfYear behaviour these two links will assist, although you will be applying the reverse transformation to their examples.

    The most ‘Pythonic’ way of doing it is to create a function. Nothing particularly special here, except the usual attempt to minimise code by doing things like day < 4 rather than day == 1 or day == 2 ... etc.

    (Of course, all of this is assuming that Python’s isocalendar correctly matches the ISO calendar. The documentation seems to suggest that it does, where the GetWeekOfYear explicitly states that it doesn’t, so it would seem a reasonable assumption. However, if this is a critical calculation, you will be testing it thoroughly yourself anyway.)

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

Sidebar

Related Questions

Is there a pythonic way of getting only certain values from a list, similar
Is there a more pythonic way to write __getitem__ than the following? The issue
Is there a Pythonic way (I mean, no pure SQL query) to define an
Is there a pythonic way to insert an element into every 2nd element in
Is there a more Pythonic way of doing this?: if self.name2info[name]['prereqs'] is None: self.name2info[name]['prereqs']
Is there a pythonic way to build up a list that contains a running
Is there a standard pythonic way to treat physical units / quantities in python?
Can anyone help me with the following query what is the pythonic way to
Is there a pythonic way to unpack a list in the first element and
Is there a pythonic way to do what the str.strip() method does, except for

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.