[DB-SIG] How deal with new datetime type breaking old colde?
Andy Dustman
farcepest at gmail.com
Mon Feb 14 16:50:03 CET 2005
On Mon, 14 Feb 2005 14:44:24 +0100, Anthra Norell
<anthra.norell at tiscalinet.ch> wrote:
> Since I upgraded to Python 2.4 all my 'select ... date ... from ...'
> commands to MySQL seem to return this format:
>
> "datetime.date ('2005', '01'. '01')"
>
> when my routines expect:
>
> "2005-01-01"
MySQLdb uses the Python built-in datetime when it is available. If you
don't like this:
db = MySQLdb.connect(...)
from MySQLdb.constants import FIELD_TYPE
del db.converter[FIELD_TYPE.DATETIME]
del db.converter[FIELD_TYPE.DATE]
del db.converter[FIELD_TYPE.TIMESTAMP]
del db.converter[FIELD_TYPE.TIME]
There are other variations on how to do this (like deleting the values
from the MySQLdb.converters.conversions, or making a custom
conversions and passing it to connect() via the conv parameter), but
by deleting the converter, you'll get the column as a string.
Or you could update your code. If you are doing any parsing of the
date at all, why not just use the datetime object?
http://docs.python.org/lib/module-datetime.html
--
Computer interfaces should never be made of meat.
Using GMail? Setting Reply-to address to <> disables this annoying feature.
More information about the DB-SIG
mailing list