Date fixed but variable month and year in python

I have below code:

from datetime import date, datetime, timedelta
from dateutil.relativedelta import relativedelta

c0 =
c1 = c0 - relativedelta(months=1)
c2 = c0 - relativedelta(months=2)
c3 = c0 - relativedelta(months=3)
c4 = c0 - relativedelta(months=4)
c5 = c0 - relativedelta(months=5)

Now date today is 2023/06/14, however what I am trying to achieve is that no matter what date it is, I should get 16 as day, and actual current month and year.

I have tried adding int to current date but since current date is not fixed, I am not able to get 16 as day.

Please suggest a way where I can convert below to a date:

day = 16
month =
year =
date = year/month/day

>Solution :

Use .replace() (on date, datetime) to edit the day component:

>>> import datetime
datetime.datetime(2023, 6, 16, 8, 35, 18, 558127)
>>>, 6, 16)

Leave a Reply