Python Calendar Module: monthdatescalendar() method
monthdatescalendar() method
The monthdatescalendar() method is used to get a list of the weeks in the month of the year as full weeks. Weeks are lists of seven datetime.date objects.
Syntax:
monthdatescalendar(year, month)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
year | Year for which the calendar should be generated. | Required | Number |
month | Month for which the calendar should be generated. | Required | Number |
Example of monthdatescalendar() method
import calendar
cal= calendar.Calendar()
print(cal.monthdatescalendar(2016, 5))
Output:
[[datetime.date(2016, 4, 25), datetime.date(2016, 4, 26), datetime.date(2016, 4, 27), datetime.date(2016, 4, 28), datetime.date(2016,4, 29),
datetime.date(2016, 4, 30), datetime.date(2016, 5, 1)], [datetime.date(2016, 5, 2), datetime.date(2016, 5, 3),
datetime.date(2016, 5, 4), datetime.date(2016, 5, 5), datetime.date(2016, 5, 6), datetime.date(2016, 5, 7), datetime.date(2016, 5, 8)],
[datetime.date(2016, 5, 9), datetime.date(2016, 5, 10), datetime.date(2016, 5, 11), datetime.date(2016, 5, 12), datetime.date(2016,
5, 13), datetime.date(2016, 5, 14), datetime.date(2016, 5, 15)], [datetime.date(2016, 5, 16), datetime.date(2016,5, 17),
datetime.date(2016, 5, 18), datetime.date(2016, 5, 19), datetime.date(2016, 5, 20), datetime.date(2016, 5, 21), datetime.date(2016, 5, 22)],
[datetime.date(2016, 5, 23), datetime.date(2016, 5, 24), datetime.date(2016, 5, 25), datetime.date(2016, 5, 26),
datetime.date(2016, 5, 27), datetime.date(2016, 5, 28), datetime.date(2016, 5, 29)], [datetime.date(2016, 5, 30), datetime.date(2016, 5, 31),
datetime.date(2016, 6, 1), datetime.date(2016, 6, 2), datetime.date(2016, 6, 3), datetime.date(2016, 6, 4),
datetime.date(2016, 6, 5)]]
Note: datetime.date
A date object represents a date (year, month and day) in an idealized calendar, the current Gregorian calendar indefinitely extended in both directions. January 1 of year 1 is called day number 1, January 2 of year 1 is called day number 2, and so on. This matches the definition of the “proleptic Gregorian” calendar in Dershowitz and Reingold’s book Calendrical Calculations, where it’s the base calendar for all computations.
Previous: itermonthdays()
Next: monthdatescalendar()
Test your Python skills with w3resource's quiz
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python/module/calendar/monthdatescalendar.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics