Affichage des articles dont le libellé est datetime. Afficher tous les articles
Affichage des articles dont le libellé est datetime. Afficher tous les articles

mercredi 26 mars 2014

datetime topic




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?






Re: datetime topic




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)







jeudi 23 janvier 2014

Re: datetime as subclass of date topic




In article <(E-Mail Removed)>,
Ben Finney <(E-Mail Removed)> wrote:

> Skip Montanaro <(E-Mail Removed)> writes:
>
> > […] I was asking [Python] if a datetime instance was an instance of a
> > date. Which, it turns out, it is.

>
> Yep. Makes sense, since ‘datetime’ can do everything ‘date’ can do, and
> is conceptually a subset of the same concept.


That's reasonable, but given that, it's weird that date(2014, 1, 23) ==
datetime(2014, 1, 23) is False. You would think it should be True, in
the same way that 1 + 0j == 1 is True.