date reformatting

Fredrik Lundh fredrik at pythonware.com
Thu Oct 6 15:08:00 EDT 2005


"Bell, Kevin" wrote:

> Anyone aware of existing code to turn a date string "8-15-05" into the
> number 20050815?

date = "8-15-05"

import re
m, d, y = map(int, re.match("(\d+)-(\d+)-(\d+)$", date).groups())
number = 20000000 + y*10000 + m*100 + d

print number

</F> 






More information about the Python-list mailing list