Convert Date to Short formate
fredrik at pythonware.com
Wed Jun 7 22:33:25 CEST 2006
> there is string value 'Dec 06, 2000' I want to convert that string
> date to SHORT FORMAT like '2000-12-06-. Please help me how do I do
you mean ISO format, right?
the easiest way is probably to use the time.strptime module to parse the
original string into a time tuple, and then use time.strftime to format
the tuple as an ISO date:
>>> s = "Dec 06, 2000"
>>> t = time.strptime(s, "%b %d, %Y")
(2000, 12, 6, 0, 0, 0, 2, 341, -1)
>>> time.strftime("%Y-%m-%d", t)
More information about the Python-list