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


Groups > comp.lang.python > #92452

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

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3a.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.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:number': 0.07; 'thats': 0.07; 'wednesday,': 0.07; 'subject:How': 0.09; 'logic': 0.09; 'may,': 0.09; 'weeks,': 0.09; 'assume': 0.11; 'wed,': 0.15; '2014': 0.16; '26th': 0.16; '28th': 0.16; 'clear.': 0.16; 'expecting': 0.16; 'inputs': 0.16; 'rough': 0.16; 'sebastian': 0.16; 'subject:between': 0.16; 'subject:dates': 0.16; 'subject:weeks': 0.16; 'sufficient,': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'code.': 0.23; '2015': 0.23; "haven't": 0.24; 'header:In- Reply-To:1': 0.24; 'checking': 0.27; 'not.': 0.27; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.28; "i'm": 0.29; '12th': 0.29; 'function': 0.30; 'code': 0.31; 'skip:d 20': 0.32; 'michael': 0.33; 'adjust': 0.33; 'point,': 0.33; 'weeks': 0.34; 'subject:?': 0.34; 'received:google.com': 0.34; 'could': 0.35; 'to:addr:python- list': 0.35; 'but': 0.36; 'week.': 0.36; 'quite': 0.37; 'two': 0.37; 'subject:: ': 0.37; 'say': 0.38; 'skip:p 20': 0.38; 'doing': 0.38; 'is,': 0.38; 'mean': 0.38; 'shared': 0.38; 'end': 0.39; 'pm,': 0.39; 'test': 0.39; 'to:addr:python.org': 0.39; 'sure': 0.40; 'even': 0.61; 'hope': 0.61; "you'll": 0.61; "you've": 0.61; 'taking': 0.62; 'total': 0.64; 'between': 0.65; 'python-list': 0.66; 'day': 0.70; '21st': 0.76; '9:19': 0.84; 'cal': 0.84; 'cheung': 0.84; 'divide': 0.84; 'to:name:python': 0.84; 'joel': 0.91; '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:content-transfer-encoding; bh=GbAs9Xq5iTI6gDpvmAny+0r/ykhpmfmJvb5RqR9oOpA=; b=Jg2enNIgJ5yPZyktcuHvuXf+G6pHdM+N/MmIoOzUJEKMESlSuIyveI9lL7O+DnofeR CG5DQ+qiJT0ZOEaaYlduZBeLmQ+yGALDmSE1LRYMRauCsS5F1eYbVdAChz74Yv6HY1uD tPHSfY1Jjr0tzd/oW45jSATaV7woNhGio3oCwEvx/8XGi6Yhl4BZwBMywxEWNaltFzwd C6RyZNQbktXEHmERslQruOzjOVG7BI1mrd4qrzOfIPjz3x/lsBeKa2nTYlPQmOW9Mi3R E4FzGuh0UhdLNf46u0m1fZEnSCI1blYzvEx0hES0Uy1OcFgwjx28HAy9MfCHD46Xlkkx 9Dwg==
X-Received by 10.129.36.14 with SMTP id k14mr8813556ywk.64.1433994372600; Wed, 10 Jun 2015 20:46:12 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <5578FE53.6090906@gmail.com>
References <a2056385-f99b-4691-9a33-5def63216e9c@googlegroups.com> <a650c18e-fa33-4139-bc68-e14b08273a8d@googlegroups.com> <5578FE53.6090906@gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 10 Jun 2015 21:45:32 -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
Content-Transfer-Encoding quoted-printable
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.381.1433994374.13271.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433994374 news.xs4all.nl 2843 [2001:888:2000:d::a6]:49508
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92452

Show key headers only | View raw


On Wed, Jun 10, 2015 at 9:19 PM, Michael Torrie <torriem@gmail.com> wrote:
> On 06/10/2015 02:11 PM, Sebastian M Cheung via Python-list wrote:
>> On Wednesday, June 10, 2015 at 6:06:09 PM UTC+1, Sebastian M Cheung wrote:
>>> Say in 2014 April to May whole weeks would be 7th, 14th 28th April and  May would be 5th, 12th and 19th. So expecting 7 whole weeks in total
>>
>> What I mean is given two dates I want to find WHOLE weeks, so if given the 2014 calendar and function has two inputs (4th and 5th month) then 7th, 14th, 21st and 28th from April with 28th April week carrying into May, and then 5th, 12th and 19th May to give total of 7 whole weeks, because 26th May is not a whole week and will not be counted.
>>
>> Hope thats clear.
>
> I think Joel had the right idea.  First calculate the rough number of
> weeks by taking the number of days between the date and divide by seven.
> Then check to see what the start date's day of week is, and adjust the
> rough week count down by one if it's not the first day of the week.  I'm
> not sure if you have to check the end date's day of week or not.  I kind
> of think checking the first one only is sufficient, but I could be
> wrong.  You'll have to code it up and test it, which I assume you've
> been doing up to this point, even though you haven't shared any code.

I don't think the logic is quite right. Consider:

>>> cal = calendar.TextCalendar()
>>> print(cal.formatmonth(2014, 6))
     June 2014
Mo Tu We Th Fr Sa Su
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

>>> date(2014, 7, 1) - date(2014, 6, 1)
datetime.timedelta(30)
>>> _.days // 7 - 1
3

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