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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:20:31+00:00 2026-06-09T13:20:31+00:00

Given a start date, how can I determine how many business weeks it’s been

  • 0

Given a start date, how can I determine how many “business weeks” it’s been with Python? I can’t just divide by 7 because that won’t give me the correct answer.

An example would be a start date of Aug 1 2012 to the current date (Aug 13 2012) would output 3 weeks.

I’m basically trying to figure out from the start of the football season, what the current week (integer) is.

I’ve tried messing around with Pythons datetime module, but it’s been to no avail.

  • 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-09T13:20:33+00:00Added an answer on June 9, 2026 at 1:20 pm

    Try using datetime.weekday, datetime.isoweekday to get the current day of the week or use the more complete datetime.isocalendar to also get the current week of the year and using those as offsets to calculate an aligned difference.

    So you can have a function like this:

    def week_difference(start, end):
        assert start <= end
        start_year, start_week, start_dayofweek = start.isocalendar()
        end_year, end_week, end_dayofweek = end.isocalendar()
    
        return ((end_year - start_year) * 52) - start_week + end_week
    

    With usage like this:

    import datetime as dt
    # same week
    In [1]: week_difference(dt.datetime(2012, 8, 1),  dt.datetime(2012, 8, 1))
    Out[1]: 0
    
    # your example (see note below) 
    In [2]: week_difference(dt.datetime(2012, 8, 1),  dt.datetime(2012, 8, 13))
    Out[2]: 2
    
    # across years
    In [3]: week_difference(dt.datetime(2011, 8, 1),  dt.datetime(2012, 8, 13))
    Out[3]: 54
    
    # year boundary: second last business week of 2011, to first business week of 2012
    # which is the same business week as the last business week of 2011
    In [4]: week_difference(dt.datetime(2011, 12, 20),  dt.datetime(2012, 1, 1))
    Out[4]: 1
    
    In [5]: week_difference(dt.datetime(2011, 12, 18),  dt.datetime(2012, 1, 1))
    Out[5]: 2
    

    You can add 1 to your week output depending on your chosen semantic of what a week difference should be.

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

Sidebar

Related Questions

Given just a std::string iterator, is it possible to determine the start and end
If I was to given a specific java.util.Date, how can I generate a start
Given a start date of 1/1/2009 and an end date of 12/31/2009, how can
How can I get the start and end date of a given year (int),
Given a table action(start:DATE, length:NUMBER, type:NUMBER), with all records unique, I need to select
how do I compute the business days in a week given the parameters: start
I need to determine if a given selection is in between a start line
Using PHP how can I get week's start date and end date from any
I have a method that takes in an id, a start date, and and
Is it possible to ser a function to start in a given date and

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.