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


Groups > comp.lang.python > #92450

Re: How to find number of whole weeks between dates?

Path csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'resulting': 0.04; 'subject:number': 0.07; 'subject:How': 0.09; '(0,': 0.09; '(1,': 0.09; '0),': 0.09; '3),': 0.09; '5),': 0.09; 'wed,': 0.15; '(2,': 0.16; '(24,': 0.16; '(3,': 0.16; '(8,': 0.16; '(9,': 0.16; '1),': 0.16; '2),': 0.16; '4),': 0.16; 'sebastian': 0.16; 'subject:between': 0.16; 'subject:dates': 0.16; 'subject:weeks': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'merge': 0.18; '>>>': 0.20; 'fairly': 0.22; '2015': 0.23; 'module': 0.23; 'third-party': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.28; 'specifically': 0.28; 'probably': 0.32; 'weeks': 0.34; 'subject:?': 0.34; 'received:google.com': 0.34; 'could': 0.35; 'to:addr:python-list': 0.35; 'library.': 0.35; 'but': 0.36; 'url:org': 0.36; 'two': 0.37; 'subject:: ': 0.37; 'list.': 0.37; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'yes': 0.60; 'python- list': 0.66; 'cheung': 0.84; 'to:name:python': 0.84; 'subject:find': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=gOLgqxgaihLlhzZ+mHxZ8V63lE5dhHVz4TwF4VfsDME=; b=MSYaWXqb7t+peZ2juYH1vSyUCckQONOl8et+X/WAWoigjF1CLu1uA/Ts21BoUS+69S +Zl0TU+An+8oGERKSTesjBFQSWj2fmaIfVpPKSlGE/YJm2ClELvc9P3zQOx6PMHC9hyT uwufmhpKTgYysGgxKp9VIT0hBmoWO6X21wTuZUFBpd12FieLQ/nfFfwa2qRnn/Y8BNx7 XDQbxjD9fl131VR7MthX8fXhmVlelwx3PyF/M2bqif4KC7xHJGWkrXtsTL9TplYdWfxk JlHlNGIXI+uaZUiUQQuVdYz7h7rNLyj2wLfFTNC8oYEnqlhUyFpYs5Z2J6KlKUwO5L4A Eg5Q==
X-Received by 10.170.69.131 with SMTP id l125mr8467687ykl.39.1433993794331; Wed, 10 Jun 2015 20:36:34 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <c62196d7-d1fb-4f0d-bb22-090aac862145@googlegroups.com>
References <a2056385-f99b-4691-9a33-5def63216e9c@googlegroups.com> <c62196d7-d1fb-4f0d-bb22-090aac862145@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 10 Jun 2015 21:35:53 -0600
Subject Re: How to find number of whole weeks between dates?
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.379.1433993802.13271.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433993802 news.xs4all.nl 2860 [2001:888:2000:d::a6]:41142
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92450

Show key headers only | View raw


On Wed, Jun 10, 2015 at 8:01 PM, Sebastian M Cheung via Python-list
<python-list@python.org> wrote:
> yes just whole weeks given any two months, I did looked into calendar module but couldn't find specifically what i need.

>>> cal.monthdays2calendar(2014, 4) + cal.monthdays2calendar(2014, 5)
[[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)], [(7, 0),
(8, 1), (9, 2), (10, 3), (11, 4), (12, 5), (13, 6)], [(14, 0), (15,
1), (16, 2), (17, 3), (18, 4), (19, 5), (20, 6)], [(21, 0), (22, 1),
(23, 2), (24, 3), (25, 4), (26, 5), (27, 6)], [(28, 0), (29, 1), (30,
2), (0, 3), (0, 4), (0, 5), (0, 6)], [(0, 0), (0, 1), (0, 2), (1, 3),
(2, 4), (3, 5), (4, 6)], [(5, 0), (6, 1), (7, 2), (8, 3), (9, 4), (10,
5), (11, 6)], [(12, 0), (13, 1), (14, 2), (15, 3), (16, 4), (17, 5),
(18, 6)], [(19, 0), (20, 1), (21, 2), (22, 3), (23, 4), (24, 5), (25,
6)], [(26, 0), (27, 1), (28, 2), (29, 3), (30, 4), (31, 5), (0, 6)]]

You just need to:

1) Trim the first and last weeks off since they contain invalid dates.
2) Merge the overlapping last week of April and first week of May.
3) Count the resulting number of weeks in the list.

Alternatively, the dateutil.rrule module could probably be used to do
this fairly easily, but it's a third-party module and not part of the
standard library.

https://labix.org/python-dateutil

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


Thread

How to find number of whole weeks between dates? Sebastian M Cheung <minscheung@googlemail.com> - 2015-06-10 10:05 -0700
  Re: How to find number of whole weeks between dates? Marko Rauhamaa <marko@pacujo.net> - 2015-06-10 20:38 +0300
    Re: How to find number of whole weeks between dates? Marko Rauhamaa <marko@pacujo.net> - 2015-06-10 20:43 +0300
    Re: How to find number of whole weeks between dates? Laura Creighton <lac@openend.se> - 2015-06-10 19:50 +0200
    Re: How to find number of whole weeks between dates? Joel Goldstick <joel.goldstick@gmail.com> - 2015-06-10 14:07 -0400
    Re: How to find number of whole weeks between dates? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-10 20:48 +0100
  Re: How to find number of whole weeks between dates? Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-10 11:42 -0600
  Re: How to find number of whole weeks between dates? Sebastian M Cheung <minscheung@googlemail.com> - 2015-06-10 13:11 -0700
    Re: How to find number of whole weeks between dates? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-10 21:26 +0100
    Re: How to find number of whole weeks between dates? Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-10 14:33 -0600
    Re: How to find number of whole weeks between dates? Michael Torrie <torriem@gmail.com> - 2015-06-10 21:19 -0600
    Re: How to find number of whole weeks between dates? Chris Angelico <rosuav@gmail.com> - 2015-06-11 13:36 +1000
    Re: How to find number of whole weeks between dates? Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-10 21:45 -0600
  Re: How to find number of whole weeks between dates? Sebastian M Cheung <minscheung@googlemail.com> - 2015-06-10 19:01 -0700
    Re: How to find number of whole weeks between dates? Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-10 21:35 -0600

csiph-web