How to tell how many weeks apart two datetimes are?
marduk at python.net
Tue Jan 8 22:31:42 CET 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?
It works for python 3(.2):
>>> x = datetime.timedelta(days=666)
>>> week = datetime.timedelta(days=7)
>>> x / week
>>> halfday = datetime.timedelta(hours=12)
>>> x / halfday
More information about the Python-list