Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:number': 0.07; 'thats': 0.07; 'wednesday,': 0.07; 'subject:How': 0.09; 'may,': 0.09; 'weeks,': 0.09; 'assume': 0.11; '2014': 0.16; '26th': 0.16; '28th': 0.16; 'clear.': 0.16; 'expecting': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 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; 'code.': 0.23; '2015': 0.23; "haven't": 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'checking': 0.27; 'not.': 0.27; "i'm": 0.29; '12th': 0.29; 'function': 0.30; 'code': 0.31; 'adjust': 0.33; 'point,': 0.33; 'weeks': 0.34; 'subject:?': 0.34; 'message- id:@gmail.com': 0.35; 'could': 0.35; 'to:addr:python-list': 0.35; 'but': 0.36; 'week.': 0.36; 'two': 0.37; 'subject:: ': 0.37; 'received:org': 0.38; 'say': 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; 'received:192': 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; 'charset:windows-1252': 0.65; 'python-list': 0.66; 'day': 0.70; '21st': 0.76; 'cheung': 0.84; 'divide': 0.84; 'joel': 0.91; 'subject:find': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Wed, 10 Jun 2015 21:19:47 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How to find number of whole weeks between dates? References: In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433992800 news.xs4all.nl 2910 [2001:888:2000:d::a6]:57092 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92445 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.