1

I have two series in my dataframe to calculate next payment date, one is start date, the other is payment frequency.

How to get the next payment date in python?

For example, the start date is 2021/12/21, and the payment frequency is 6 months, I want to get the next payment date of 2022/6/21.

Zhao
  • 41
  • 3
  • https://stackoverflow.com/questions/546321/how-do-i-calculate-the-date-six-months-from-the-current-date-using-the-datetime – leo Jul 18 '22 at 15:21

1 Answers1

1

Using the parser module from dateutil library you can parse the start date text into a datetime.datetime object. With relativedelta from the same library you can advance time in that datetime object. Here's an code example:

from dateutil import parser
from dateutil.relativedelta import relativedelta

start_date = parser.parse("2021/12/21")
end_date = start_date + relativedelta(months=+6)

print(start_date)
print(end_date)

Output:

2021-12-21 00:00:00
2022-06-21 00:00:00
Adilius
  • 308
  • 2
  • 10