-
-
Couldn't load subscription status.
- Fork 33.3k
Closed as not planned
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
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
yearandmontharguments. - As an instance method it would return a last day of a month for a
dateinstance.
from datetime import date
date.end_of_month(2025, 11) # 2025-11-30
date.today().end_of_month() # 2025-10-31It 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:
Goldenanviljewelers
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
No status