> In a datetime object I would like to change days and hours.

you'd been pointed to the resources yesterday - please read manuals
carefully!

a = datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)
b = a + datetime.timedelta(days=-2, hours=-4)
 
<Newbie Question>
  
But wont this create a new object? Whereas if you want to modify the same object, should we not be using replace? Or does it not matter in the global picture?
 
>>> a = datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)
>>> b = a + datetime.timedelta(days=-2, hours=-4)
>>>
>>>
>>> id(a)
21838592
>>> id(b)
21836312
>>> a.replace(day=a.day + 1)
datetime.datetime(2006, 8, 13, 10, 13, 56, 609000)
>>> id(a)
21838592
>>>
 
</Newbie Question>
 
thanks,
Rama
 
     

 

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to