开发者

How to find difference in time from current date and a pre-determined date in python? [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜