Po开发者_高级运维ssible Duplicate:
How do I find the time difference between two datetime objects in python?
I am trying to find the difference in the number of days between current time and a given time in python.
For example, the time given is 2011-07-20 and the difference in the number of days at the point of posting this question is 41 days.
So my question is, how do I convert the given time into something that I can use to find the time difference in days. I am trying to make use of datetime.timedelta.now() - given time.
Thank you!
Sure something like this:
from datetime import datetime
d = datetime.now()
d1 = datetime.strptime('2011-07-20', '%Y-%m-%d')
(d-d1).days
>>> 42 # number of total days beetween two given dates
Find more on strptime using the following link.
精彩评论