Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get end of next month

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading