[Tutor] A question about: Adding seconds to datetime object

Asrarahmed Kadri ajkadri at googlemail.com
Sat Nov 18 18:24:24 CET 2006


Thanks.

It means, you take a datetime object and then using a timedelta object,
perform the addition, the language takes care of changing the date if the
time crosses midnight.
WOW... this makes life a lot easier..

Have a brilliant evening.
Best Regards,
Asrarahmed Kadri


On 11/18/06, Kent Johnson <kent37 at tds.net> wrote:
>
> Asrarahmed Kadri wrote:
> > Hi ,
> >
> >
> > I have a question:
> >
> > Is it possible to add seconds to a datetime object and get the result as
> > a new datetime object. I mean when we keep adding, for example, 3600
> > seconds, the date will get changed after 24 iterations. Is it possible
> > to carry out such an operation ?
>
> Sure, just add a datetime.timedelta to the datetime object:
>
> In [1]: from datetime import datetime, timedelta
>
> In [2]: d=datetime.now()
>
> In [3]: d
> Out[3]: datetime.datetime(2006, 11, 18, 9, 47, 31, 187000)
>
> In [4]: delta=timedelta(seconds=3600)
>
> In [5]: d+delta
> Out[5]: datetime.datetime(2006, 11, 18, 10, 47, 31, 187000)
>
> Kent
>
>


-- 
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061118/46a28a62/attachment.html 


More information about the Tutor mailing list