How to tell how many weeks apart two datetimes are?
marduk
marduk at python.net
Tue Jan 8 16:31:42 EST 2013
On Tue, Jan 8, 2013, at 04:22 PM, 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?
> --
> http://mail.python.org/mailman/listinfo/python-list
It works for python 3(.2):
>>> x = datetime.timedelta(days=666)
>>> week = datetime.timedelta(days=7)
>>> x / week
95.14285714285714
>>> halfday = datetime.timedelta(hours=12)
>>> x / halfday
1332.0
More information about the Python-list
mailing list