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

John Machin sjmachin at lexicon.net
Sun Mar 15 23:25:42 CET 2009


On Mar 16, 6:55 am, John Yeung <gallium.arsen... at gmail.com> wrote:
> 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.

A couple of issues here:

(1) The number of days in a month is not a constant, so "a
mathematician's sense of logic" is quite irrelevant.

(2) The various *different* LPDMs are quite well established and each
of them can be reduced to non-ambiguous rules provided that the
reducer is patient and persistent and avoids terms like "ugly",
"illogical", "ludicrous" ... early stages of the reduction process can
produce things like "31 January plus 1 month -> 3 March (2 March in a
leap year)" :-)



More information about the Python-list mailing list