Home > python > ValueError: Unsupported format character ‘Y’

ValueError: Unsupported format character ‘Y’

Problem: Getting above value error in python when I use the following.

query = “””SELECT DATE_FORMAT(date_time,’%Y-%m-%d’) AS date
FROM table
WHERE col = %s”””

cursor.execute(query, [pram1])

Solution:
Escape the % signs in the date.

query = “””SELECT DATE_FORMAT(date_time,’%%Y-%%m-%%d’) AS date
FROM table
WHERE col = %s”””

cursor.execute(query, [pram1])

Categories: python Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.