1import calendar
2from datetime import datetime
3
4year = 2020
5month = 1
6
7rng = calendar.monthrange(year, month) # (2, 31)
8last_day = datetime(year, month, rng[1])
9
10# calendar.monthrange returns tuple in the format of
11# (<day of week>, <last day>). day of week is 0 indexed
12# starting on Monday
13#
14# 0 = Monday
15# 1 = Tuesday
16# 2 = Wednesday
17# 3 = Thursday
18# 4 = Friday
19# 5 = Saturday
20# 6 = Sunday
21