RovKat
RovKat

Reputation: 37

Need to get output of all weekdays starting from given date

Output is not how it should be

given_day = datetime.date(2022,10,31)
    dates = given_day + datetime.timedelta(days=+1)
    for i in range(0 - given_day.weekday(), 7 - given_day.weekday()):
        print(given_day.strftime("%A"))

Output should start from Monday and end to Sunday Output I get is: Monday Monday Monday Monday Monday Monday Monday Where i made a mistake :(

Upvotes: 0

Views: 15

Answers (1)

TheEagle
TheEagle

Reputation: 5992

I can't make head or tail of your code, but the following works:

given_day = datetime.date(2022,10,31)
for i in range(0 + given_day.weekday(), 7):
    print(given_day.strftime("%A"))
    given_day += datetime.timedelta(days=1)

Upvotes: 1

Related Questions