How to calculate difference between two dates in weeks in python

前端 未结 6 1527
花落未央
花落未央 2020-12-02 23:02

I\'m trying to calculate the difference between two dates in \"weeks of year\". I can get the datetime object and get the days etc but not week numbers. I can\'t, of course,

6条回答
  •  天涯浪人
    2020-12-02 23:31

    This is a very simple solution with less coding everyone would understand.

    from datetime import date
    
    d1 = date(year, month, day)
    d2 = date(year, month, day)
    result = (d1-d2).days//7
    

提交回复
热议问题