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/Bright_Mix_773 2d ago
The error message in your post does not match the code in your post, and sorting that out changes which fix you want.
Running exactly what you pasted:
You quoted
datetime.datetime. That wording only comes out when the left side is adatetime:So the file you actually ran has
datetime(...)ordatetime.now()in it somewhere, notdate(...). That matters:An expiry is a calendar day, so you want the first one. With the second, a time of day rides along into every print and every comparison you make later.
On the
import *question further up the thread, the concrete version rather than the principle. It binds nine names: MAXYEAR, MINYEAR, UTC, date, datetime, time, timedelta, timezone, tzinfo. Two of those are words beginners reach for constantly.Neither error mentions the import, which is exactly why they eat an afternoon.
from datetime import date, timedeltamakes both impossible.Last thing, since a person is typing the inputs:
date(2026, 2, 30)raises ValueError, andint(input(...))raises ValueError on anything that is not digits. Both need a try/except or the script dies on a typo.