Recently for one of my requirement, I had to find the number of weeks in a given month including partial weeks. There are several ways to find this. The method I followed is by using the len() function around calendar.monthcalendar() method. Here is syntax and an example.
Syntax
len(calendar.monthcalendar(year, month))
Example
import calendar
Year_given = 2019
for month_no in range(1,13):
print("\nWeeks in", calendar.month_name[month_no], Year_given, ": ", \
len(calendar.monthcalendar(Year_given, month_no)))
More Tips
- Finding number of weeks in a month in SQL Server.
- Getting week number in a month for the given date in Python.
Reference
- More about calendar.monthcalendar at Python docs.