# of Months between two dates
Joel Goldstick
joel.goldstick at columbuswebmakers.com
Sun Aug 8 14:24:50 EDT 2010
Greg Lindstrom wrote:
> 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
>
>
y_diff = present year - start date year
m_diff = present month - start date month + (12 * y_diff)
More information about the Python-list
mailing list