Search code examples
pythondatetimercountdown

Python Get Date In Future (x) Days, And Hours Left To Date?


How can I get date + time in the future from now by days? in this format: 10/08/2013 9:50 PM (dd/mm/yyyy) and also I would like Time left to date in hours for this new future date?


Solution

  • You need to use a datetime in combination with a timedelta object.

    Like this:

    from datetime import datetime, timedelta
    dt = datetime.now()
    td = timedelta(days=4)
    # your calculated date
    my_date = dt + td