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


Groups > comp.lang.python > #69147

Re: datetime

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'argument': 0.05; 'string.': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:/ 10': 0.09; 'epoch': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subtract': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'convenient': 0.24; 'header:X-Complaints-To:1': 0.27; '>>>>': 0.31; 'perl': 0.31; 'yesterday': 0.31; 'skip:d 20': 0.34; 'could': 0.34; 'add': 0.35; 'there': 0.35; "i'll": 0.36; 'seconds': 0.37; 'feed': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'easy': 0.60; 'today,': 0.61; 'name': 0.63; 'today': 0.64; 'this...': 0.84; 'victor': 0.84; 'tomorrow': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: datetime
Date Wed, 26 Mar 2014 22:33:32 +0100
Organization None
References <CABLWypNDCGcojSWR_Dp9NKJtEQH9cshgTZoY=7cm6Ye9_Ai73g@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd99e0.dip0.t-ipconnect.de
User-Agent KNode/4.11.5
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8590.1395869628.18130.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1395869628 news.xs4all.nl 2923 [2001:888:2000:d::a6]:46188
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69147

Show key headers only | View raw


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


Thread

Re: datetime Peter Otten <__peter__@web.de> - 2014-03-26 22:33 +0100

csiph-web