Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #92449
| 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 | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.031 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'subject:number': 0.07; 'subject:How': 0.09; 'rounding': 0.09; 'cc:addr:python-list': 0.10; 'assume': 0.11; "hasn't": 0.15; 'thu,': 0.15; 'boundary,': 0.16; 'did,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'rough': 0.16; 'subject:between': 0.16; 'subject:dates': 0.16; 'subject:weeks': 0.16; 'sufficient,': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'code.': 0.23; '2015': 0.23; 'this:': 0.23; "haven't": 0.24; 'header:In-Reply-To:1': 0.24; 'checking': 0.27; 'not.': 0.27; 'message-id:@mail.gmail.com': 0.28; "i'm": 0.29; 'there.': 0.30; 'code': 0.31; 'skip:d 40': 0.32; 'michael': 0.33; 'adjust': 0.33; 'point,': 0.33; 'definition': 0.34; 'weeks': 0.34; 'subject:?': 0.34; 'previous': 0.34; 'received:google.com': 0.34; 'could': 0.35; 'next': 0.35; 'skip:d 30': 0.35; 'something': 0.35; 'represent': 0.35; 'but': 0.36; 'week.': 0.36; 'there': 0.36; 'subject:: ': 0.37; 'doing': 0.38; 'is,': 0.38; 'shared': 0.38; 'end': 0.39; 'pm,': 0.39; 'test': 0.39; 'sure': 0.40; 'your': 0.60; 'even': 0.61; "you'll": 0.61; "you've": 0.61; 'taking': 0.62; 'complete': 0.63; 'between': 0.65; 'day': 0.70; 'chrisa': 0.84; 'divide': 0.84; 'loose': 0.84; 'twelve': 0.84; 'to:none': 0.90; '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:date:message-id:subject:from:cc :content-type; bh=h+cEUqIVwm3uFqyh7/YlJlq4gS31laPRxaYyu48pgJk=; b=G3OYnh9pJXHHcy9Epz3FODPVn5twl2f29y/R/at0X7rXwVEIsoFb4HqnWBxfk+IMHZ lO4LH36LPjDr+9hmTFNx7o0Y25ZyyqeLiYWSH4CUsDIKZgtwnpWpev32AW6wOcWrjeDy fSPCgCiVo01WrDByWsbmJ1F4UM9urvMb0Yt/PTaOfBgXLjYzv43sNVdu1p8MKCB2V8Zy Ea42R6lF1Ll+WhwhdBSGRcYn08JnN9jHwps0OaI6dIRe4pVODe+5jFrCZPKnQTHutaWy Ujp93gI5ImLDfbDEpO1Bf4XK7VtVD77K2cir3M48/WycCi0EHhYL8oso5BhPX6jskMxB Hxbg== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.141.164 with SMTP id rp4mr32185887igb.2.1433993775527; Wed, 10 Jun 2015 20:36:15 -0700 (PDT) |
| 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> |
| Date | Thu, 11 Jun 2015 13:36:15 +1000 |
| Subject | Re: How to find number of whole weeks between dates? |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <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.378.1433993784.13271.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1433993784 news.xs4all.nl 2844 [2001:888:2000:d::a6]:40764 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:92449 |
Show key headers only | View raw
On Thu, Jun 11, 2015 at 1:19 PM, Michael Torrie <torriem@gmail.com> wrote: > 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. Alternatively, you could start by rounding the start date up to the next week boundary, then round the end date down to the previous week boundary, and then calculate from there. Something like this: >>> start = datetime.date(2015, 1, 4) >>> end = datetime.date(2015, 4, 2) >>> start += datetime.timedelta(7-start.isoweekday()) >>> end -= datetime.timedelta(end.isoweekday() % 7) Now both dates represent Sundays. If either already did, it hasn't been changed. >>> (end - start).days//7 12 There are twelve complete Sunday-to-Sunday weeks (plus any loose days either end) between the original dates. Depending on your definition of "complete week", you may need to adjust this code some. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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