Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Date Parsing Question

Reply
Thread Tools

Date Parsing Question

 
 
Gavin
Guest
Posts: n/a
 
      09-03-2010
Hi,

I'm using the python-dateutil package : http://labix.org/python-dateutil
to parse a set of randomly formatted strings into dates. Because the
formats are varied, I can't use time.strptime() because I don't know
what the format is upfront.

python-dateutil seems to work very well if everything is in English,
however, it does not seem to work for other languages and the
documentation does not seem to have any information about locale
support.

Here's an example showing my problem:

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from dateutil.parser import *
>>> import datetime
>>> import time
>>> date_string1 = time.strftime("%Y-%B-%d %H:%M:%S",(2010,10,3,1,1,1,1,1,1))
>>> print date_string1

2010-October-03 01:01:01
>>> parse(date_string1)

datetime.datetime(2010, 10, 3, 1, 1, 1)

everything is ok so far, now retry with a date in german:

>>> import locale
>>> locale.setlocale(locale.LC_ALL, "german")

'German_Germany.1252'
>>> locale.getlocale()

('de_DE', 'cp1252')

>>> date_string1 = time.strftime("%Y-%B-%d %H:%M:%S",(2010,10,3,1,1,1,1,1,1))
>>> print date_string1

2010-Oktober-03 01:01:01
>>> parse(date_string1)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'date_string' is not defined
>>> parse(date_string1)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python26\lib\site-packages\python_dateutil-1.5-py2.6.egg
\dateutil\parser.py", line 697, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "c:\python26\lib\site-packages\python_dateutil-1.5-py2.6.egg
\dateutil\parser.py", line 303, in parse
raise ValueError, "unknown string format"
ValueError: unknown string format


Am I out of luck with this package? Just wondering if anyone has used
this to work with non-english dates. I'm also open to other ideas to
handle this.

Appreciate the assistance,

Gavin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing date from sql string in asp.net, then comparing it with present date .Net Sports ASP .Net 1 06-24-2005 11:35 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C Programming 3 11-08-2003 09:07 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57