time.strftime in 2.4.1 claims data out of range when not
Kent Johnson
kent37 at tds.net
Fri Apr 22 08:26:02 EDT 2005
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