How to calculate number of days between two given dates?

前端 未结 13 1292
梦如初夏
梦如初夏 2020-11-22 06:29

If I have two dates (ex. \'8/18/2008\' and \'9/26/2008\'), what is the best way to get the number of days between these two dates?

相关标签:
13条回答
  • 2020-11-22 06:56

    Days until Christmas:

    >>> import datetime
    >>> today = datetime.date.today()
    >>> someday = datetime.date(2008, 12, 25)
    >>> diff = someday - today
    >>> diff.days
    86
    

    More arithmetic here.

    0 讨论(0)
提交回复
热议问题