Bug in strptime?
timr at probo.com
Wed Oct 29 07:59:53 CET 2003
"Henk-Jan de Jong" <henkjan at xs4all.nl> wrote:
>I'm completely new in Python and have the next problem. I have a huge file
>with dates a want to convert from one format to another.
>e.g 31-12-2003 should become 31122003. I'm using the next piece of code:
>def changeDate(inDate, inFormat, outFormat):
> return strftime(outFormat, strptime(inDate, inFormat))
>#the next part inside the loop reading the file:
>newDate = changeDate(oldDate, "%d-%m-%Y", "%d%m%Y")
It probably won't help you know, but this is certainly not the way I would
have solved this problem. There isn't any particular reason why you should
go to the trouble to treat these as dates, since you aren't really using
the values. Thus, this would be a LOT quicker:
newDate = oldDate.replace('-','')
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list