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


Groups > comp.lang.python > #36456

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'mrab': 0.05; 'allowed.': 0.07; 'subject:two': 0.07; 'subject:How': 0.09; 'python': 0.09; 'be:': 0.09; 'sep': 0.09; '2.7.3': 0.16; '22:50,': 0.16; 'roy': 0.16; 'subject:weeks': 0.16; 'to:name:python list': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'import': 0.21; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'appear': 0.26; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'division': 0.29; 'to:addr:python-list': 0.33; 'weeks': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'false': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'more': 0.63; 'beat': 0.65; 'smith': 0.71; '2013': 0.84; 'are?': 0.84; 'oscar': 0.84; 'subject:tell': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=3p75M23KgkJ1mGHqqWfwkQkZT3/PNDICJPf2FklBIeo=; b=iVFkPb4d879itM2e7pP/T90C7t3yQbrVoCu/swisOFGFhspoY/IykjqmsUnEklnQco EQk3Mgq2R9atD6Fg2urGhsW41w6jFCloSyOEubh6IXxqT1vYCknAaQQJX2o6A0fJH1TU Nap4q4b2U+lpnWYe3rcEKqLXuVptpv+aMXmMoe1A18azsckaJAciGgGEmVDCdmMzPrvc m9KxuAhHOm379aiXrknqs3encNWm5Ol3J/+k+CZlBzYS8TXFXAAjcwLP9jDaqMpEMFAe nntDYUQz3xmvDHg6M8VBCeAQdzZ+6Y6UgbqRW/7O8PX4/yk41PDyosSi6WadPYeEBWID 0kPw==
MIME-Version 1.0
In-Reply-To <50ECA2C1.1000305@mrabarnett.plus.com>
References <kci2m1$fp4$1@panix2.panix.com> <50ECA2C1.1000305@mrabarnett.plus.com>
Date Tue, 8 Jan 2013 22:54:20 +0000
Subject Re: How to tell how many weeks apart two datetimes are?
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
To Python List <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.295.1357685662.2939.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357685662 news.xs4all.nl 6941 [2001:888:2000:d::a6]:36677
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36456

Show key headers only | View raw


On 8 January 2013 22:50, MRAB <python@mrabarnett.plus.com> wrote:
> 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

You beat me to it...

$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> dt1 = datetime.datetime.now()
>>> dt2 = dt1 - datetime.timedelta(days=8)
>>> (dt2 - dt1) / 7 > datetime.timedelta(days=14)
False


Oscar

Back to comp.lang.python | Previous | NextPrevious 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