[Tutor] datetime: What happended yesterday? :-)

doug shawhan doug.shawhan at gmail.com
Mon Jun 12 22:20:41 CEST 2006


Heh. Your example would look very, very nice in the timedelta (
http://docs.python.org/lib/datetime-timedelta.html) section of the docs! :-)

It makes perfect sense, the authors probably thought it was too easy to need
an explaination ...

On 6/12/06, Kent Johnson <kent37 at tds.net> wrote:
>
> doug shawhan wrote:
> > I've been looking at datetime and cannot figure out what was a very
> > simple operation with the time module.
> >
> > How does one add or subtract 24 (or any number) of hours from a given
> > date and time using the datetime module?
>
> Use a datetime.timedelta:
>
> In [1]: import datetime
>
> In [2]: now = datetime.datetime.now()
>
> In [3]: now
> Out[3]: datetime.datetime(2006, 6, 12, 16, 7, 47, 69000)
>
> In [4]: one_day = datetime.timedelta(hours=24)
>
> In [5]: now-one_day
> Out[5]: datetime.datetime(2006, 6, 11, 16, 7, 47, 69000)
>
> Kent
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060612/7a16065d/attachment.html 


More information about the Tutor mailing list