Using Python to count the number of business days in a month?

后端 未结 6 864
南旧
南旧 2021-01-05 18:27

I am trying to write a Python script that will calculate how many business days are in the current month. For instance if month = August then businessDays

6条回答
  •  长发绾君心
    2021-01-05 18:43

    You could take a look at datetime.datetime.dayofweek() but if you are not allowed to use an external library then you need to:

    1. pick a date that you know the day of week of - best if it is a Monday
    2. come up with a formulae for the number of days since then that the first of a given month is.
    3. for each of the days in the month the (number of days since your day) % 7 in [5, 6] is a weekend.

提交回复
热议问题