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?
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?
you can use relativedelta https://dateutil.readthedocs.io/en/stable/relativedelta.html
month_end = <your datetime value within the month> + relativedelta(day=31)
that will give you the last day.I hope,It's usefull for very much..Try it on this way..we must need import some package
Here is a solution based python lambdas:
The
next_month
lambda finds the tuple representation of the first day of the next month, and rolls over to the next year. Themonth_end
lambda transforms a date (dte
) to a tuple, appliesnext_month
and creates a new date. Then the "month's end" is just the next month's first day minustimedelta(days=1)
.