How to find number of whole weeks between dates?

Ian Kelly ian.g.kelly at gmail.com
Wed Jun 10 13:42:00 EDT 2015


On Wed, Jun 10, 2015 at 11:05 AM, Sebastian M Cheung via Python-list
<python-list at python.org> wrote:
> Say in 2014 April to May whole weeks would be 7th, 14th 28th April and  May would be 5th, 12th and 19th. So expecting 7 whole weeks in total

>>> from datetime import date
>>> d1 = date(2014, 4, 7)
>>> d2 = date(2014, 5, 19)
>>> d2 - d1
datetime.timedelta(42)
>>> (d2 - d1).days
42
>>> (d2 - d1).days // 7
6



More information about the Python-list mailing list