(no subject)
sismex01 at hebmex.com
sismex01 at hebmex.com
Fri Jun 6 09:46:35 EDT 2003
More information about the Python-list mailing list
Fri Jun 6 09:46:35 EDT 2003
- Previous message (by thread): (no subject)
- Next message (by thread): (no subject)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> From: Leeds, Mark [mailto:mleeds at mlp.com] > Sent: Thursday, June 05, 2003 6:12 PM > > I have another date question : > > Now I have dates that are of the form > > 2/14/1980 so > I tried to read them in using > > Temptime = time.strptime(filedate,"%m" + "//" + "%d" + "//" + > "%Y") But > I get some weird error like format mismatch. > > Could it be because the date is 2/14 instead of 02/14 ? > > This will be my last question about dates. > > mark > You *could* use a regular expression to reformat the date, something like this: Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> import re >>> rxDate = re.compile(r"(\d{1,2})/(\d{1,2})/(\d{4})") >>> def ReformatDate(dateString): date = rxDate.search(dateString) if date: return "%02d/%02d/%04d" % tuple(map(int,date.groups())) raise ValueError("Date has inappropriate format: %s" % dateString) >>> ReformatDate("3/6/1969") '03/06/1969' >>> hth. -gca -- Advertencia:La informacion contenida en este mensaje es confidencial y restringida, por lo tanto esta destinada unicamente para el uso de la persona arriba indicada, se le notifica que esta prohibida la difusion de este mensaje. Si ha recibido este mensaje por error, o si hay problemas en la transmision, favor de comunicarse con el remitente. Gracias.
- Previous message (by thread): (no subject)
- Next message (by thread): (no subject)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list