Quick Python question

Christopher Schmidt crschmidt-cTEUcjrfgDqB+jHODAdFcQ at public.gmane.org
Thu Oct 8 11:28:08 EDT 2009


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)

-- Chris

> In the above case I'm setting a date object d to todays date, then
> advancing it to the next year. Is there a more elegant or efficient way
> of doing this in Python. The above method certainly works fine except
> for February 29th, which is not important. 
> 
>    
> 
> -- 
> Jerry Feldman <gaf-mNDKBlG2WHs at public.gmane.org>
> Boston Linux and Unix
> PGP key id: 537C5846
> PGP Key fingerprint: 3D1B 8377 A3C0 A5F2 ECBB  CA3B 4607 4319 537C 5846
> 
> 


> _______________________________________________
> Discuss mailing list
> Discuss-mNDKBlG2WHs at public.gmane.org
> http://lists.blu.org/mailman/listinfo/discuss


-- 
Christopher Schmidt
MetaCarta





More information about the Discuss mailing list