Bell, Kevin wrote:
> Anyone aware of existing code to turn a date string "8-15-05" into the
> number 20050815?
>>> import datetime
>>> s = "8-15-05"
>>> month,day,year = map(int, s.split('-'))
>>> date = datetime.date(2000+year,month,day)
>>> date.strftime('%Y%m%d')
'20050815'
Of course, if
setup.py install
--
http://mail.python.org/mailman/listinfo/python-list
There's more than one way, but this one will work for
dates prior to 2000.
import time
datestring='8-15-05'
d=time.strptime(datestring,'%m-%d-%y')
number=1*d[0]+100*d[1]+d[2]
print number
-Larry Bates
Bell, Kevin wrote:
> Anyone aware of existing code to turn a date string "8-15-05" into the
"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 = 2000 + y*1 + m*100 + d
print number
--
http://mail.python.org/mai
Anyone aware of existing code to turn a date string "8-15-05" into the
number 20050815?
The dateutil module has a parse method that looks perfect, I downloaded
and unzipped it, but could figure out how to install it. I using
windows XP and py2.4.
Any ideas?
Kev
--
http://mail.python.org/m