Reputation: 5
I'm trying to subtract two user input days. The user would input the start and end date in the format of (YYYYMMDD). So far the code below is what I have but I keep getting a TypeError.
import sys, datetime
startDate = sys.argv[1]
endDate = sys.argv[2]
d1 = datetime.date(startDate, "%Y-%m-%d")
d2 = datetime.date(endDate, "%Y-%m-%d")
print d1, d2
Upvotes: 0
Views: 61
Reputation: 4572
You're calling date()
incorrectly. See https://docs.python.org/2.7/library/datetime.html#date-objects
It wants, 3 integers. Year, month, day.
datetime.date(2020, 11, 9)
The error message is telling you that putting the string "%Y-%m-%d"
in the arguments is not correct.
TypeError: an integer is required (got type str)
Upvotes: 1