Home > Enterprise >  I want to count subscription days
I want to count subscription days

Time:05-21

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 )

CodePudding user response:

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.

CodePudding user response:

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
  • Related