How to add months to a date (datetime object)?

John Yeung gallium.arsenide at gmail.com
Sun Mar 15 20:55:13 CET 2009


On Mar 15, 3:10 pm, Casey Webster <Casey... at gmail.com> wrote:
> The example you give does have fairly obvious logic. But how does it
> handle Feb 28th, 2009 + 3 months?  To me, there are two "obvious"
> answers: May 28th, 2009 or May 31st, 2009.  The question is intent; is
> Feb 28th an arbitrary day of the month, or is it the last day of the
> month, which for something like a monthly bill reminder is more likely?

In my experience, unless there is explicit verbiage that says "last
day of the month", the day of the month is always retained except
where it would result in an invalid date.  (So May 28 in your
example.)

I sympathize with anyone who considers "lay person date math" ugly and
not always logical, in a mathematician's sense of logic.  But the fact
of the matter is that LPDM is quite well established and not very
ambiguous at all.

John



More information about the Python-list mailing list