Re: date diff calc

2004-12-02 Thread David Fraser
Peter Hansen wrote: Tim Peters wrote: [Peter Hansen] I think Skip was intending that the format string be mandatory, to avoid such ambiguity. It's still a bottomless pit -- ask Brett, who implemented the Python strptime . True, I did overlook timezones at the time. On the other hand, that's b

Re: date diff calc

2004-11-30 Thread Peter Hansen
Tim Peters wrote: [Peter Hansen] I think Skip was intending that the format string be mandatory, to avoid such ambiguity. It's still a bottomless pit -- ask Brett, who implemented the Python strptime . True, I did overlook timezones at the time. On the other hand, that's because *my* use cases

Re: date diff calc

2004-11-30 Thread Peter Hansen
Tim Peters wrote: [Skip Montanaro] I think inputs from strings would be much more common. Me too, although it's a bottomless pit. guess-6-intended-meanings-for-1/2/3-before-breakfast-ly y'rs I think Skip was intending that the format string be mandatory, to avoid such ambiguity. At least, that's w

Re: date diff calc

2004-11-30 Thread Tim Peters
[Skip Montanaro] >>> I think inputs from strings would be much more common. [Tim Peters] >> Me too, although it's a bottomless pit. >> >> guess-6-intended-meanings-for-1/2/3-before-breakfast-ly y'rs [Peter Hansen] > I think Skip was intending that the format string be mandatory, > to avoid such a

Re: date diff calc

2004-11-29 Thread Tim Peters
[Skip Montanaro] > ... > The datetime.date object already exposes a strftime method for > generating a formatted string output and will create date objects > from both time.time() output (fromtimestamp) and "proleptic > Gregorian ordinal"s (fromordinal). Looking at the datetime module > docs, it's

Re: date diff calc

2004-11-29 Thread Rick Holbert
Here's how to do it as a one-liner: python -c "import datetime; import time; print 'Only %d days until Christmas' % (datetime.date(2004, 12, 25) - datetime.date.fromtimestamp(time.time())).days" Here's a slightly shorter way of doing it: python -c "import time; print 'Only %f more days until Ch

Re: date diff calc

2004-11-29 Thread Skip Montanaro
tertius> Is there a more pythonic way to write or do a date difference tertius> calculation? I have as input two date fields in the form tertius> '-MM-DD' How about: import datetime import time bd = "2004-11-25" ed = "2004-11-30" start = datetime.date.fromti

Re: date diff calc

2004-11-29 Thread tertius
Diez B. Roggisch wrote: > I can't imagine what could possibly be easier than subtracting two dates - in fact, most times one has to jump through much more hoops to achieve these results, e.g. in java. I'll try that. Thanks, T -- http://mail.python.org/mailman/listinfo/python-list

Re: date diff calc

2004-11-29 Thread Diez B. Roggisch
> bdl = '2004-11-25'.split('-') > edl = '2004-11-30'.split('-') > bd = date(int(bdl[0]), int(bdl[1]), int(bdl[2])) > ed = date(int(edl[0]), int(edl[1]), int(edl[2])) using time.strptime and datetime.date.fromtimestamp is surely the better alternative, as it lets specify you the format by a str

date diff calc

2004-11-29 Thread tertius
Hi, Is there a more pythonic way to write or do a date difference calculation? I have as input two date fields in the form '-MM-DD' TIA Terius from datetime import date bdl = '2004-11-25'.split('-') edl = '2004-11-30'.split('-') bd = date(int(bdl[0]), int(bdl[1]), int(bdl[2])) ed = date(in