Python calendar module | itermonthdates() method
Calendar module allows to output calendars like program, and provides additional useful functions related to the calendar. Functions and classes defined in Calendar module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions.
itermonthdates() method returns an iterator for the month (1–12) in the year. This iterator will return all days for the month and all days before the start of the month or after end of the month that are required to get a complete week.
Syntax: itermonthdates(year, month) Parameter: year: year of the calendar month: month of the calendar Returns: an iterator for the month.
Code #1:
# Python program to demonstrate working # of itermonthdates() method # importing calendar module from calendar import Calendar obj = calendar.Calendar() # iteratign with itermonthdates for day in obj.itermonthdates(2018, 9): print(day) |
Output:
2018-08-27 2018-08-28 2018-08-29 2018-08-30 2018-08-31 . . . 2018-09-26 2018-09-27 2018-09-28 2018-09-29 2018-09-30
Code #2:
# Python program to demonstrate working # of itermonthdates() method # importing calendar module import calendar # use with firstweekday = 5 obj = calendar.Calendar(firstweekday = 5) # iteratign with itermonthdates for day in obj.itermonthdates(2018, 4): print(day) |
Output:
2018-08-30 2018-08-31 2018-09-01 2018-09-02 2018-09-03 . . 2018-09-30 2018-10-01 2018-10-02 2018-10-03 2018-09-01 2018-09-02 2018-09-03 . . 2018-09-28 . . 0018-03-31 0018-04-01 0018-04-02 . . 2018-04-28 2018-04-29 2018-04-30 2018-05-01 2018-05-02
Recommended Posts:
- Python calendar module | setfirstweekday() method
- Python calendar module | leapdays() method
- Python calendar module | yeardayscalendar() method
- Python calendar module | yeardays2calendar() method
- Python calendar module | pryear() method
- Python calendar module | formatmonth() method
- Python calendar module | firstweekday() method
- Python calendar module | formatyear() method
- Python calendar module | isleap() method
- Python calendar module | prmonth() method
- Python calendar module | yeardatescalendar() method
- Python calendar module | monthdatescalendar() method
- Python calendar module | itermonthdays() method
- Python calendar module | iterweekdays() method
- Python calendar module | monthdayscalendar() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



