I’m trying to make a object with the same year and month as the current date but change the day around to a different date in the month.
from datetime import timedelta, date, datetime
whole = date.today()
wholestr= str(whole)
vali = wholestr.split('-')
year=int(vali[0])
month=int(vali[1])
day=int(vali[2])
sub = datetime.date(year,month,16)
print sub
Here it says that ints work when constructing but I get an error saying that it needs a datetime.date obj and not ints.
I believe your problem is that you call
datetime.datewhen you just want to calldatein your second to last line. Changing to just usingdategave me this result:Alternatively you could just call
datetimelike this:Personally, this is why I always prefer to just do
import datetime.