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


Groups > comp.lang.python > #92413

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

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: How to find number of whole weeks between dates?
Date 2015-06-10 20:38 +0300
Organization A noiseless patient Spider
Message-ID <877frbwjik.fsf@elektro.pacujo.net> (permalink)
References <a2056385-f99b-4691-9a33-5def63216e9c@googlegroups.com>

Show all headers | View raw


Sebastian M Cheung <minscheung@googlemail.com>:

> 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

This program gives you the number of days between two dates given in the
YYYY-MM-DD format:

========================================================================
#!/usr/bin/env python3

import sys

def gregorian_day_count(isodate):
    year, month, day = map(int, isodate.split('-'))
    a, b = divmod(12 * year + month - 3, 12)
    return (a * 365 + (a >> 2) - (a * 1311 >> 17) + (a * 1311 >> 19) +
            + (31306 * b + 722 >> 10))

def main():
    print(gregorian_day_count(sys.argv[2]) - gregorian_day_count(sys.argv[1]))

if __name__ == '__main__':
    main()
========================================================================

Divide the number by 7 and you have your answer.


Marko

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