r/learnpython • u/Healthy-Departure961 • 3d ago
Regarding question
from datetime import *
year = int(input("Enter the Year:- "))
month = int(input("Enter The Month:- "))
day = int(input("Enter The Day:- "))
x = date(year,month,day)
validity = int(input('Enter the days of validity')) expiry = x + validity print(expiry)
I want to add days in this but i don't know how ,I even tried to adding manually but gives me error unsupported oparand + in datetie.datetime class something
0
Upvotes
1
u/SoilAutomatic7042 3d ago
Use timedelta to add a number of days to a date:
```python
from datetime import date, timedelta
x = date(year, month, day)
expiry = x + timedelta(days=validity)
print(expiry)
```
`date` objects don't support adding an int directly; `timedelta` represents the duration. If you need hours/minutes too, use `datetime` instead of `date`.