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
The datetime() constructor in python accepts year, month and date values as parameters and create a datetime object. Pass the year, month and day values of the desired date object (as my_date. year, my_date. month, my_date.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With