Skip to content

datetime: getting the last day of a month #140015

@m-aciek

Description

@m-aciek

Feature or enhancement

Proposal:

Currently to get the last day of the month, the most straightforward method is:

from calendar import monthrange
from datetime import date

mydate = date.today()

mydate.replace(day=monthrange(mydate.year, mydate.month)[1])  # date(2025, 10, 31)

I'd like to propose adding an end_of_month() method to the date class.

  • As a class method it would return a last day of month for year and month arguments.
  • As an instance method it would return a last day of a month for a date instance.
from datetime import date

date.end_of_month(2025, 11)  # 2025-11-30
date.today().end_of_month()  # 2025-10-31

It can be achieved with a “hybrid method” for Python implementation.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/idea-date-end-of-month/

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions