# of Months between two dates

Greg Lindstrom gslindstrom at gmail.com
Sun Aug 8 15:40:48 CEST 2010


I work for a company that processes claims for the health care industry
(Novasys Health, recently purchased by Centene Corp).  My current assignment
has me writing a routine to compute insurance premiums.  One of the
requirements is to determine how many months a policy has been in effect.
The datetime module will give me the number of days but, with months having
different lengths, that does not do me much good.  I've looked in the
calendar library but didn't see anything there, either.

I've written a function to return the months between date1 and date2 but I'd
like to know if anyone is aware of anything in the standard library to do
the same?  For bonus points, does anyone know if postgres can do the same
(we use a lot of date/time funcitons in postgres, already, but didn't see
this problem addressed).

On a side note; since I'm dealing with money (USD), I decided to use the
decimal module for all computations.  It's not a big difference -- unless
you've seen the movie "Office Space" :-) -- but it sure is nice.  Especially
being able to easily round values to the nearest cent.  You just have to
love the standard library.

Thanks for your help,
--greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100808/617ff7ba/attachment.html>


More information about the Python-list mailing list