PKV
PKV

Reputation: 177

Get the date of last day of next month based on a given date

I have a pandas dataframe with a column consisting of dates and the type of the column is datetime64[ns]. I'm trying to get the date of the last day of next month.

For example, I have 2020-11-30 and my code is returning 2020-12-30, but I would like to get 2020-12-31 (since the next month (December) has 31 days). My code is simply adding +1 to the month, but I would also like to get the last day too.

My current code is as follows:

def inc_date(bdx_dt):
    return pd.Timestamp(bdx_dt) + pd.DateOffset(months=1)

my_table['REPORTING_DT_python'] = my_table.apply(lambda row:inc_date(row['BDX_DT']), axis=1)

My current output:

enter image description here

However, I would like to get:

enter image description here

Please help. Thanks in advance.

Upvotes: 1

Views: 70

Answers (0)

Related Questions