Bug in strptime?
Henk-Jan de Jong
henkjan at xs4all.nl
Wed Oct 29 14:27:40 EST 2003
Hello Tim,
I'm trying to make a generic routine for date-conversions. In my example the
format changes from dd-mm-yyyy to ddmmyyyy. I'm doing lots of
data-conversions, so a next time I maybe want to convert ddmmyyyy to
yyyymmdd or whatever. Furtermore the conversion-rules are described in an
xml-file for automatic processing:
eg. xml-description of the field in infile:
.
.
<field format="%d-%m-%Y"></field>
.
.
xml-description of the field in oufile:
.
.
<field format="%Y%m%d"></field>
.
.
If there is less complex way to get it done, I'd be interested to see how. I
bought my first Python book last weekend, so I've a lot to learn :))
Greetinx
Matuka
"Tim Roberts" <timr at probo.com> wrote in message
news:t8pupvk00tth0dat7b5oos7l7kvj59r44n at 4ax.com...
> "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
mailing list