Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Quick Python question



On Thu, Oct 08, 2009 at 11:28:08AM -0400, Christopher Schmidt wrote:
> On Thu, Oct 08, 2009 at 11:03:38AM -0400, Jerry Feldman wrote:
> > Recently, I've had to start writing some Python code. My question is
> > specific to the datetime object.
> > Basically, given a date, I need to add years to that date. One way to do
> > it is:
> > 
> > from datetime import date
> > d = date.today() # initialize d to some date
> > d = date(d.year + 1, d.month, d.day)
> 
> atetime.datetime.now()+datetime.timedelta(365)

> > of doing this in Python. The above method certainly works fine except
> > for February 29th, which is not important. 

Why isn't February 29th important?

And what happens on leapyears, anyway?

Is the spec "do something more-or-less a year from now" or "do
something 365 days from now" or "do something on the next
anniversary of this date, treat February 29th as either Feb 28
or Mar 1"?

(Christopher's example is a right thing to do, and certainly
uses the right method -- the question is whether the logic
matches what you want to do.)

-dsr-


-- 
http://tao.merseine.nu/~dsr/eula.html is hereby incorporated by reference.
You can't defend freedom by getting rid of it.






BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org