Hello! I'm fairly new to Python. Hopefully you can understand what I'm trying to accomplish here. I'm making a GUI that prints Parking Garage Tickets. I want to be able to post an expiration date on the ticket. I found out about timedelta, and it works if I put in, for example, datetime.timedelta(days=4). However, in my program, I have an entry box that allows the user to enter how many days they will be parking for. Is there a way to make timedelta accept a variable in between the parentheses? For example: timedelta(days=n), where n is the amount of days the user entered.

Here is what I have so far:

today = datetime.date.today()
        future = datetime.timedelta(days=4)
        expire = today + future
        date = Text(Point(250,185), expire)
        date.setFill("blue")
        date.draw(win)

If someone could please show me how to make it so that timedelta accepts a variable instead of a literal number? Thanks.. let me know if you need more information.

import datetime
today = datetime.date.today()
time_to_stay = int(raw_input('Number of days you want to stay: '))
future = datetime.timedelta(days=time_to_stay)
expire = today + future
print(expire)

Thank you! It's working perfectly now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.