Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69148

Re: datetime

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: datetime
Date 2014-03-27 08:36 +1100
References <CABLWypNDCGcojSWR_Dp9NKJtEQH9cshgTZoY=7cm6Ye9_Ai73g@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.8591.1395869819.18130.python-list@python.org> (permalink)

Show all headers | View raw


Victor Engle <victor.engle@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: datetime Ben Finney <ben+python@benfinney.id.au> - 2014-03-27 08:36 +1100

csiph-web