3 ms·
I would have changed the following two lines, that way, you don't have to know what the last day of the month is. end_date = datetime(2023, 7, 1) # ...
by gabrielsroka 3y ago
I would have changed the following two lines, that way, you don't have to know what the last day of the month is.
end_date = datetime(2023, 7, 1)
# ...
while current_date < end_date:
This is a lot shorter though maybe harder to read:
>>> import calendar
>>> c = calendar.Calendar()
>>> sum(d > 0 and calendar.MONDAY <= w <= calendar.FRIDAY for d, w in c.itermonthdays2(2023, 6))
22
https://docs.python.org/3/library/calendar.html#calendar.Calendar.itermonthdays2 https://docs.python.org/3/library/calendar.html#calendar.Cal...