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 430009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:49:54+00:00 2026-05-12T19:49:54+00:00

The Python datetime.isocalendar() method returns a tuple (ISO_year, ISO_week_number, ISO_weekday) for the given datetime

  • 0

The Python datetime.isocalendar() method returns a tuple (ISO_year, ISO_week_number, ISO_weekday) for the given datetime object. Is there a corresponding inverse function? If not, is there an easy way to compute a date given a year, week number and day of the week?

  • 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-12T19:49:55+00:00Added an answer on May 12, 2026 at 7:49 pm

    Python 3.8 added the fromisocalendar() method:

    >>> datetime.fromisocalendar(2011, 22, 1)
    datetime.datetime(2011, 5, 30, 0, 0)
    

    Python 3.6 added the %G, %V and %u directives:

    >>> datetime.strptime('2011 22 1', '%G %V %u')
    datetime.datetime(2011, 5, 30, 0, 0)
    

    Original answer

    I recently had to solve this problem myself, and came up with this solution:

    import datetime
    
    def iso_year_start(iso_year):
        "The gregorian calendar date of the first day of the given ISO year"
        fourth_jan = datetime.date(iso_year, 1, 4)
        delta = datetime.timedelta(fourth_jan.isoweekday()-1)
        return fourth_jan - delta 
    
    def iso_to_gregorian(iso_year, iso_week, iso_day):
        "Gregorian calendar date for the given ISO year, week and day"
        year_start = iso_year_start(iso_year)
        return year_start + datetime.timedelta(days=iso_day-1, weeks=iso_week-1)
    

    A few test cases:

    >>> iso = datetime.date(2005, 1, 1).isocalendar()
    >>> iso
    (2004, 53, 6)
    >>> iso_to_gregorian(*iso)
    datetime.date(2005, 1, 1)
    
    >>> iso = datetime.date(2010, 1, 4).isocalendar()    
    >>> iso
    (2010, 1, 1)
    >>> iso_to_gregorian(*iso)
    datetime.date(2010, 1, 4)
    
    >>> iso = datetime.date(2010, 1, 3).isocalendar()
    >>> iso
    (2009, 53, 7)
    >>> iso_to_gregorian(*iso)
    datetime.date(2010, 1, 3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a datetime.time value in Python, is there a standard way to add an
I have a Python datetime.datetime object. What is the best way to subtract one
I would like to find out if a particular python datetime object is older
Python uses the reference count method to handle object life time. So an object
In this Python package there is this code: >>> dt = DateTime('Mar 9, 1997
Why doesn't the following work (Python 2.5.2)? >>> import datetime >>> class D(datetime.date): def
I'd like to be able to create a datetime object with datetime.datetime.now() PyYAML. It's
Possible Duplicates: Python - easy way to add N seconds to a datetime.time? How
How do I get the modified date/time of a file in Python?
Python has this wonderful way of handling string substitutions using dictionaries: >>> 'The %(site)s

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.