I created a function to get date from the user and convert it into datetime
format using strptime
. The function is called Obtaindate()
. This will go as input into another function Getdata()
. Now, in the second function Getdata()
I need to subtract the date from Obtaindate()
with timedelta
. But I get the error TypeError: unsupported operand type(s) for -: 'NoneType' and 'datetime.timedelta'
.
What should I do to get the date from the 1st function to work in the second function?
Here is the code sample:
def ObtainDate():
isValid=False
while not isValid:
userin = str(input("Type Date ddmmyy: "))
try:
dt = datetime.datetime.strptime(userin, '%d%m%y')
print('You have selected {}'.format(datetime.date.strftime(dt, '%d-%b-%Y')))
break
except:
print("Incorrect format...try again!")
continue
return dt
ObtainDate()
def Getdata():
date1 = ObtainDate() - datetime.timedelta(1)
date2 = datetime.datetime.today()
delta = datetime.timedelta(1)
while date1 < date2:
print('Download in progress...')