Python - itermonthdates()


Python tip:

You can get an iterator for a certain month by using the itermonthdates method. You need to provide a year and a month as parameters.

The iterator returns all days before the start / after the end of the month that are required to get a full week.

import calendar

cal = calendar.Calendar()

for day in cal.itermonthdates(2022, 7):
    print(day)

"""
Results:

2022-06-27
2022-06-28
2022-06-29
2022-06-30
2022-07-01
2022-07-02

...

2022-07-30
2022-07-31
"""