Python Forum

Full Version: Would like to input a date variable and determine whether it is within the time range
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i am new to programming. I would like to create a program which i could input a date variable and if the date variable is not within the range, it would produce another result.

import datetime
d1 = datetime.date(2019,1,1)
d2 = datetime.date(2019,1,30)
inputd_v = datetime.date("Please input date: ")
if inputd_v > d1 < d2:
    print (d1)
else:
    print ("Your date is out of range")
Please assist as right this program. Thanks!
If you can use an external library, I'd suggest dateutil
>>> from dateutil.parser import parse
>>> parse("2019 1 5").date()
datetime.date(2019, 1, 5)
>>> parse("2019 jan 5").date()
datetime.date(2019, 1, 5)
>>> parse("2019 5 january").date()
datetime.date(2019, 1, 5)
>>> parse("january 5").date()
datetime.date(2019, 1, 5)
Also don't write if inputd_v > d1 < d2:, write if d1 < inputd_v < d2. inputd_v needs to be a date instance, not a string.
Noted on the BBCode Gribouillis, however the program is still unable to work.
Quote: however the program is still unable to work.
What does python say? do you have an exception traceback? Oh I see, you forgot to use input, input("Please input date: ")