Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (1.6k points)
Is there a way using Python's standard library to easily determine (i.e. one function call) the last day of a given month?

If the standard library doesn't support that, does the dateutil package support this?

1 Answer

0 votes
by (25.1k points)

You can simply use the monthrange methods from python's calendar. This method will return a tuple with first element as start of the month and second element as the end of the month. So to get the last day of the month.

module.calendar.monthrange(year, month)[1]

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...