'I want to count subscription days

I want to count subscription days i tried using timedelta() but I need to skip Thursday while calculating, its a 26 day subscription but no delivery on Thursday

started = datetime.date(2022 , 5 , 22 )
subscription  = datetime.timedelta(26)

print( started+subscription )


Solution 1:[1]

To count (increment daily) or to calculate ? Calculation is a calendar problem - you need to calculate the number of exclusion days (Thursdays's).

Your case is easy since there is always exactly 4 Thursdays in any 26-day calendar span.

Solution 2:[2]

Both datetime.date and datetime.datetime objects have a today method that return respectively a Date and a Datetime object.

Which both have a weekday and isoweekday methods. weekday count from Monday = 0, while isoweekday count from Monday = 1:

from datetime import date, datetime
if date.today().weekday() == 0:
    # it is Monday
if datetime.today().isoweekday() == 1:
   # it is Monday

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ZXX
Solution 2 Kshitiz305