views:

182

answers:

1

Given that foo is a valid datetime object in python,

One can change the hour represented in a datestamp (foo) by doing something something like:

foo2 = foo.replace( hour=5 ) 

Rather then replacing the hour with a particular value ( as is done above )..is it possible to increment the time in foo by say, 5 hours ? Something along the lines of:

foo2 = foo.replace( hour += 5 ) 

Which I know is not correct...but maybe that explains better what I am aiming to do...

I am limited to using python 2.5.1 ( the version on OS X 10.5.x) .. and am not able to add any modules such as pyTZ

+3  A: 

That's what timedelta is for:

>>> import datetime
>>> d = datetime.datetime(2010, 12, 25, 18, 25)
>>> d + datetime.timedelta(hours = 8)
datetime.datetime(2010, 12, 26, 2, 25)
balpha
@balpha Perfect.. thanks
CaseyIT