I have a SQLite3 database where date and time is stored as a string like "Tue Aug 06 20:13:58 CEST 2013"
, and I need to extract some of the data into a CSV file.
I know how to open the database, connection, and cursor (reading), and how to open the output CSV file for writing (using the csv
module).
The datetime string should be converted to the "YYYYMMDD"
string -- i.e. "20130806"
in the above case.
My idea was to use the datetime.datetime.strptime("Tue Aug 06 20:13:58 CEST 2013"
, frm)
to get the datetime
object that would be later used for producing the formatted vallue. However, I get the following error:
Traceback (most recent call last):
File "a.py", line 18, in <module>
dt = datetime.datetime.strptime(s, frm)
File "C:\Python33\lib\_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "C:\Python33\lib\_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data 'Tue Aug 06 20:13:51 CEST 2013' does not match format
'%a %b %m %H:%M:%S %Z %Y'
I thought it can be problem with the locale, as I am using...
>>> import locale
>>> locale.getdefaultlocale()
('cs_CZ', 'cp1250')
However, I am not able to set the locale to 'en'
, en_us
, or the like:
>>> locale.setlocale(locale.LC_ALL, 'en')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python33\lib\locale.py", line 541, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
I need your eyes and experience.