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?

References <a2056385-f99b-4691-9a33-5def63216e9c@googlegroups.com> <c62196d7-d1fb-4f0d-bb22-090aac862145@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-06-10 21:35 -0600
Subject Re: How to find number of whole weeks between dates?
Newsgroups comp.lang.python
Message-ID <mailman.379.1433993802.13271.python-list@python.org> (permalink)

Show all headers | 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