Datetime question

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Aug 3 08:53:25 EDT 2006


In <1154607991.404201.23400 at p79g2000cwp.googlegroups.com>, Lad wrote:

> In a datetime object I would like to change days and hours.
> Or in other words, I would like to copy this datetime object but
> increase days and hours.
> Is it possible?
> For example:If I have a datetime object like this
> datetime.datetime(2006, 8, 3, 14, 13, 56, 609000)
> 
> I would like to make a new ,for example like this
> 
> datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)
> 
> is it possible to do so?

Yes it is, just add a `timedelta` object:

In [18]: a = datetime.datetime(2006, 8, 3, 14, 13, 56, 609000)

In [19]: a + datetime.timedelta(days=8, hours=20)
Out[19]: datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list