How to tell how many weeks apart two datetimes are?

Ian Kelly ian.g.kelly at gmail.com
Tue Jan 8 22:36:08 CET 2013


On Tue, Jan 8, 2013 at 2:33 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Tue, Jan 8, 2013 at 2:22 PM, Roy Smith <roy at panix.com> wrote:
>> How do you tell how many weeks apart two datetimes (t1 and t2) are?
>> The "obvious" solution would be:
>>
>> weeks = (t2 - t1) / timedelta(days=7)
>>
>> but that doesn't appear to be allowed.  Is there some fundamental
>> reason why timedelta division not supported?
>
> Seems to be supported in Python 3.3, but not in 2.7.

>From the docs:

Changed in version 3.2: Floor division and true division of a
timedelta object by another timedelta object are now supported, as are
remainder operations and the divmod() function. True division and
multiplication of a timedelta object by a float object are now
supported.



More information about the Python-list mailing list