Datetime question

Rama ramasubramani.g at gmail.com
Thu Aug 3 09:32:35 EDT 2006


>
> > 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060803/b50eea80/attachment.html>


More information about the Python-list mailing list