itermonthdays4()

Calendar Module

monthMonth number for which dates are requried
yearYear number for which dates are requried
itermonthdays4() : Returns an Iterator of tuples having day , month year and week day for the month.

Week day number starts from 0 as Monday , 1 as Tuesday and ends at 6 as Sunday.

Note that tuple will be returned per the days for the week starting from Previous month and for days for the week extended up to next month.
Year is our first or 0th element of the tuple. Month is the second element and day is the third element of the tuples. Week day is 4th element of the tuple

import calendar
my_cal= calendar.Calendar()
for x in my_cal.itermonthdays4(2020,7):
	print(x)
Output
(2020, 6, 29, 0)
(2020, 6, 30, 1)
(2020, 7, 1, 2)
(2020, 7, 2, 3)
(2020, 7, 3, 4)
(2020, 7, 4, 5)
---------------
---------------
(2020, 7, 26, 6)
(2020, 7, 27, 0)
(2020, 7, 28, 1)
(2020, 7, 29, 2)
(2020, 7, 30, 3)
(2020, 7, 31, 4)
(2020, 8, 1, 5)
(2020, 8, 2, 6)
By updating the first day of the week we can get different elements of the iterator.
import calendar
my_cal= calendar.Calendar(firstweekday=3)
for x in my_cal.itermonthdays4(2020,7):
	print(x)
Output
(2020, 6, 25, 3)
(2020, 6, 26, 4)
(2020, 6, 27, 5)
(2020, 6, 28, 6)
(2020, 6, 29, 0)
(2020, 6, 30, 1)
(2020, 7, 1, 2)
(2020, 7, 2, 3)
(2020, 7, 3, 4)
---------------
---------------
(2020, 7, 30, 3)
(2020, 7, 31, 4)
(2020, 8, 1, 5)
(2020, 8, 2, 6)
(2020, 8, 3, 0)
(2020, 8, 4, 1)
(2020, 8, 5, 2)
As we are getting tuple as output, we can get first element as year , 2nd as month and 3rd as day the month. 4th element is week day in number
import calendar
my_cal= calendar.Calendar(firstweekday=3)
for x in my_cal.itermonthdays4(2020,7):
	print('Year:',x[0],', Month : ',x[1],', Day : ',x[2],', Week Day : ',x[3])
Output
Year: 2020 , Month :  6 , Day :  25 Week Day :  3
Year: 2020 , Month :  6 , Day :  26 Week Day :  4
Year: 2020 , Month :  6 , Day :  27 Week Day :  5
Year: 2020 , Month :  6 , Day :  28 Week Day :  6
Year: 2020 , Month :  6 , Day :  29 Week Day :  0
Year: 2020 , Month :  6 , Day :  30 Week Day :  1
Year: 2020 , Month :  7 , Day :  1 Week Day :  2
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
Year: 2020 , Month :  7 , Day :  29 Week Day :  2
Year: 2020 , Month :  7 , Day :  30 Week Day :  3
Year: 2020 , Month :  7 , Day :  31 Week Day :  4
Year: 2020 , Month :  8 , Day :  1 Week Day :  5
Year: 2020 , Month :  8 , Day :  2 Week Day :  6
Year: 2020 , Month :  8 , Day :  3 Week Day :  0
Year: 2020 , Month :  8 , Day :  4 Week Day :  1
Year: 2020 , Month :  8 , Day :  5 Week Day :  2
Calendar Module in Python itermonthdays() itermonthdays2() itermonthdays3()




plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer