time.strftime in 2.4.1 claims data out of range when not

Moderator Moderator
Fri Apr 22 11:39:57 EDT 2005


Hello,

Thank you to all who replied. Yes, obviously the extra values I'm passing are 
out of range, such as the ordinal day-number of the year. Oy.

I've been having a number of issues with switching from 2.2.2 to 2.4.1 and 
last night when I started trying to address this problem (at a late hour) I'm 
afraid my thunker sure wasn't thunking.

I like the datetime.date suggestion best, probably.

Again, thanks, and this will help me to get through this niggle...

Sheila King
http://www.thinkspot.net/sheila/

On Fri, 22 Apr 2005 05:26:02 -0700, Kent Johnson wrote
(in article <4268e904$1_2 at newspeer2.tds.net>):

> Raymond Hettinger wrote:
>> Since the rules for handling missing, inconsistent, or out-of-range tuple 
>> fields
>> are not defined, even that revision has some risk.  To future-proof the 
>> code,
>> use strptime() to generate a well-formed time tuple:
>> 
>>>>> strptime('%d-%d-%d' % (y,m,d), '%Y-%m-%d')
>> 
>> (2005, 5, 15, 0, 0, 0, 6, 135, -1)
>> 
>>>>> strftime("%Y-%m-%d", _)
>> 
>> '2005-05-15'
> 
> or use datetime.date which only needs y, m, d:
> 
>   >>> from datetime import date
>   >>> d=date(2005, 5, 15)
>   >>> d.strftime("%Y-%m-%d")
> '2005-05-15'
> 
> Kent





More information about the Python-list mailing list