Here is some prototyping code that given two dates will print the time between them:
from datetime import datetime
date_format= "%m/%d/%y"
now=datetime.now()
print now
d1=datetime.now()
d2=datetime.strptime('07/21/14',date_format)
delta= d2-d1
print delta
I'd like to modify this, such that it asks the user for two dates, instead of hardcoding the date in the source code.
So far, I've written:
date1=raw_input("What is date 1 ?:")
print date1
date2=raw_input("What is date 2 ?:")
print date2
delta=date2-date1
print delta
But after I type in my dates, I get the error:
Traceback (most recent call last):
File "C:/Python27/datetimetest.py", line 17, in <module>
delta=date2-date1
TypeError: unsupported operand type(s) for -: 'str' and 'str'