datetime

Ben Finney ben+python at benfinney.id.au
Wed Mar 26 22:36:42 CET 2014


Victor Engle <victor.engle at gmail.com> writes:

> It would be convenient if datetime.date.today() accepted an argument
> as an offset from today, like datetime.date.today(-1). Is there an
> easy way to do this with datetime?

The types defined in ‘datetime’ can perform calendar arithmetic::

    import datetime

    today = datetime.date.today()
    one_day = datetime.timedelta(days=1)
    yesterday = today - one_day
    tomorrow = today + one_day

<URL:http://docs.python.org/3/library/datetime.html#datetime.timedelta>

-- 
 \        “Most people, I think, don't even know what a rootkit is, so |
  `\     why should they care about it?” —Thomas Hesse, Sony BMG, 2006 |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list