Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36454

Re: How to tell how many weeks apart two datetimes are?

References <kci2m1$fp4$1@panix2.panix.com> <CALwzid=_jmXEMVHMo5OnkAvFaQVrUMt9KYO8wb1PP4m-fZpXtQ@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2013-01-08 14:36 -0700
Subject Re: How to tell how many weeks apart two datetimes are?
Newsgroups comp.lang.python
Message-ID <mailman.293.1357681002.2939.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Jan 8, 2013 at 2:33 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Tue, Jan 8, 2013 at 2:22 PM, Roy Smith <roy@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to tell how many weeks apart two datetimes are? roy@panix.com (Roy Smith) - 2013-01-08 16:22 -0500
  Re: How to tell how many weeks apart two datetimes are? marduk <marduk@python.net> - 2013-01-08 16:31 -0500
  Re: How to tell how many weeks apart two datetimes are? Ian Kelly <ian.g.kelly@gmail.com> - 2013-01-08 14:33 -0700
  Re: How to tell how many weeks apart two datetimes are? Ian Kelly <ian.g.kelly@gmail.com> - 2013-01-08 14:36 -0700
  Re: How to tell how many weeks apart two datetimes are? MRAB <python@mrabarnett.plus.com> - 2013-01-08 22:50 +0000
  Re: How to tell how many weeks apart two datetimes are? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-08 22:54 +0000

csiph-web