Skip to main content

Fetch the last day of the month in Python

Published 1 min readMarkdown
Fetch the last day of the month in Python

Python does not have a simple method to fetch the last day of the month. Instead, you need to use the monthrange() method from the calendar module as shown here. Not an inconvenience really.. 🤷‍♂️

>>> import calendar
>>> calendar.monthrange(2022, 2)[1]
28

Thanks for reading :)

About the author

  • I am a developer sharing the problems I solve through my blog. Just giving back to the community I learned so much from! Have an amazing day :)

No comments yet. Be the first to comment.