How to tell how many weeks apart two datetimes are?

MRAB python at mrabarnett.plus.com
Tue Jan 8 23:50:41 CET 2013


On 2013-01-08 21:22, Roy Smith 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?
>
Try this:

weeks = (t2 - t1).days / 7




More information about the Python-list mailing list