mysql and DATE format

Preston Landers prestonlanders at
Thu Nov 25 01:32:06 CET 1999

Sounds like you need to either prefix your % symbols in the command with
a backslash, and/or use raw strings.

Try this:

"... DATE_FORMAT(date, \"\%W, \%d \%b \%Y\"), ..."

hope that helps. If that doesn't help, try prefixing the entire string
with the letter r and read the revelant sections of the documentation
(search for 'raw string' on the Python website.)


In article <81hhm6$ba2$1 at>,
  sp00fD <sp00fD at> wrote:
> I've currently got some perl code that executes a sql statment which
> looks like:
> SELECT id, subject, author, text, DATE_FORMAT(date, \"%W, %d %b %Y\"),
> DATE_FORMAT(date, \"%h:%i %p\") FROM Table WHERE thread=18 ORDER by
> date desc
> When trying to use that in python like this:
> """SELECT .. DATE... FROM %s WHERE thread=%d""" % (table, id)
> it tries to expand the DATE %W.. variables.
> I've also tried it as
> sql = 'SELECT id, subject, author, text, '
> sql = sql + 'DATE_FORMAT(date, \"%W, %d %b %Y\"), '
> sql = sql + 'DATE_FORMAT(date, \"%h:%i %p\") FROM' + table
> sql = sql + 'WHERE thread=' + id + 'ORD...'
> which gives me a TypeError: illegal argument type for built-in
> operation.  Why?  How can I do this properly?
> Sent via
> Before you buy.

|| Preston Landers <prestonlanders at> ||

Sent via
Before you buy.

More information about the Python-list mailing list