I want to take in a string that is a date (ex. "2002-3-14") and turn it into total days since January 1st 1 AD (ex. 730,924). How would I do this in python 2.7? Is there a way to convert the datetime to a timedelta?
Asked
Active
Viewed 1,113 times
1 Answers
0
import datetime
d0 = datetime.datetime.strptime("0001-1-01", "%Y-%m-%d")
df = datetime.datetime.strptime("2002-3-14", "%Y-%m-%d")
print(df-d0)
>> 730922 days, 0:00:00

Charles Clayton
- 17,005
- 11
- 87
- 120