Add a month

Gregory Piñero gregpinero at gmail.com
Fri Feb 17 17:13:58 EST 2006


Ok, 30 minutes later, here's my best solution.

http://www.answermysearches.com/index.php/how-to-add-months-to-a-date-in-python/53/

(Posted on my website to make sure tabs are kept.)

Would someone mind double-checking my logic before I put this into
production next Tuesday?

-Greg


On 2/17/06, Gregory Piñero <gregpinero at gmail.com> wrote:
> Actually, no wait, that's bad.  It doesn't increment the year.
>
> Does anyone have a simple way to code this?
>
> -Greg
>
>
> On 2/17/06, Gregory Piñero <gregpinero at gmail.com> wrote:
> > Here's how I do it:
> >
> > def monthify(anint):
> >     if anint%12==0:return 12
> >     else:return anint%12
> >
> > import datetime
> > d=datetime.datetime.today()
> > dplus1month=datetime.datetime(d.year,monthify(d.month+1),d.day)
> >
> > We need monthify because adding 1 to 12 is bad otherwise!
> >
> > -Greg
> >
> > On 17 Feb 2006 04:15:39 -0800, Paul Boddie <paul at boddie.org.uk> wrote:
> > > Fredrik Lundh wrote:
> > > >
> > > > what do you expect d_new to be after the operation ?  if the answer
> > > > is date(2006,3,17), what's date(2006,1,31) plus one month?
> > >
> > > February 31st, of course:
> > >
> > > http://sql-info.de/mysql/gotchas.html#1_14
> > >
> > > ;-)
> > >
> > > Paul
> > >
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
> > >
> >
> >
> > --
> > Gregory Piñero
> > Chief Innovation Officer
> > Blended Technologies
> > (www.blendedtechnologies.com)
> >
>
>
> --
> Gregory Piñero
> Chief Innovation Officer
> Blended Technologies
> (www.blendedtechnologies.com)
>


--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)



More information about the Python-list mailing list