There is a date like this:
Timestamp('2020-10-17 00:00:00')
How can I get the end of next month?
The output should be like this:
Timestamp('2020-11-30 00:00:00')
I tried rrule
but it does not work correctly.
My Code:
import pandas as pd
from datetime import date
from dateutil.rrule import rrule, MONTHLY
start_date = date(2020, 9, 17)
end_date = date(2020, 10, 31)
for d in rrule(MONTHLY, dtstart=start_date, until=end_date):
t = pd.Timestamp(d)
print(t)
The output:
2020-09-17 00:00:00
2020-10-17 00:00:00
I am going to get end of month.
>Solution :
in my case, change first day of next 2 month.
and then minus 1 day.
i also use this in java.
sample code
import pandas as pd
t = pd.Timestamp('2020-10-17 00:00:00')
t = t.replace(day=1)
answer = t + pd.DateOffset(months=2) + pd.DateOffset(days=-1)