pythonpython-dateutilrrule

How to generate the next six months?


I'm trying to create this template. Expect to receive September 30, 2022 or October 1, 2022

But I get the next year the same day!

>>> datetime.today()
datetime.datetime(2022, 3, 31, 9, 21, 49, 315991)
>>> rrule.rrule(freq=rrule.MONTHLY, interval=6, dtstart=datetime.today()).after(datetime.today())
datetime.datetime(2023, 3, 31, 9, 18, 3)

EDIT

I want to get a series of dates (every 6 month) and take the nearest:

rrule.rrule(freq=rrule.MONTHLY, interval=6, dtstart=some_date).after(datetime.today())

Solution

  • rrule.rrule(rrule.DAILY, dtstart=dt_start, interval=183).after(datetime.today())