How to find number of whole weeks between dates?

Joel Goldstick joel.goldstick at gmail.com
Wed Jun 10 14:07:46 EDT 2015


On Wed, Jun 10, 2015 at 1:50 PM, Laura Creighton <lac at openend.se> wrote:
> In a message of Wed, 10 Jun 2015 20:38:59 +0300, Marko Rauhamaa writes:
>>Divide the number by 7 and you have your answer.
>>
>
> I am not sure that is what he wants -- If he gives us a start of Tuesday the
> 9th of June 2015 (yesterday) and an end of Thursday the 25th of June, that's
> 16 days.  But there is only one Monday-Friday week in there, the 14th-19th.
>
> So if the OP wants an answer of 1 for such data, he may be interested in
> the python calendar module https://docs.python.org/2/library/calendar.html
>
> Laura
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Find the number of weeks with the above method, then

>>> import datetime
end_date = datetime.datetime(2012, 3, 23)  // whatever your end date is
if end_date.weekday() != 5:
    number_of_complete _weeks -= 1

weekday returns 0 for monday, so 5 for Saturday


-- 
Joel Goldstick
http://joelgoldstick.com



More information about the Python-list mailing list