Categories
Python Answers

How to get the last day of the month with Python?

Spread the love

Sometimes, we want to get the last day of the month with Python.

In this article, we’ll look at how to get the last day of the month with Python.

How to get the last day of the month with Python?

To get the last day of the month with Python, we call the calendar.monthrange method.

For instance, we write

import calendar

d =  calendar.monthrange(2022, 1)

to get the last day of January 2022 by calling calendar.monthrange with the year and month.

Conclusion

To get the last day of the month with Python, we call the calendar.monthrange method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *