Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69147
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: datetime |
| Date | 2014-03-26 22:33 +0100 |
| Organization | None |
| References | <CABLWypNDCGcojSWR_Dp9NKJtEQH9cshgTZoY=7cm6Ye9_Ai73g@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8590.1395869628.18130.python-list@python.org> (permalink) |
Victor Engle wrote: > I want to keep a collection of data organized by collection date and I'll > use datetime like this... > >>>> datetime.date.today() > > datetime.date(2014, 3, 26) > > > I'll format the date and create directories like /mydata/yyyy-mm-dd > > > When I create a directory for today, I need to know the directory name for > yesterday and tomorrow. In perl I could get seconds since the epoch using > time and then add or subtract from that number for tomorrow or yesterday > and feed that into localtime to get the date string. > > > 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? >>> import datetime >>> ONE_DAY = datetime.timedelta(days=1) >>> today = datetime.date.today() >>> today datetime.date(2014, 3, 26) >>> today - ONE_DAY datetime.date(2014, 3, 25) >>> today + ONE_DAY datetime.date(2014, 3, 27)
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: datetime Peter Otten <__peter__@web.de> - 2014-03-26 22:33 +0100
csiph-web