开发者

How much days left from today to given date

I have a date - 开发者_开发问答2015.05.20

What is the best way to calculate using python how much days left from today till this date?

from datetime import *
today = date.today()
future = date(2015,05,20)
???


import datetime

today = datetime.date.today()
future = datetime.date(2019,9,20)
diff = future - today
print (diff.days)

diff is a timedelta object.


subtract them.

>>> from datetime import *
>>> today = date.today()
>>> future = date(2015,05,20)
>>> str(future - today)
'1326 days, 0:00:00'
>>> (future - today).days
1326
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜