0

This is my sample query.py

class Query:
     XYZ = """ select * from table where date_format(created_at, '%Y-%m-%d') = '{date}' """

In my main.py

current_date = datetime.now().strftime('%Y-%m-%d')

def example():
    df = pd.read_sql(Query.XYZ.format(date=current_date), self.db)
    print(df)

I'm using SQLAlchemy.

But I'm ending up with this error ValueError: unsupported format character 'Y' (0x59) at index 309. I read others solution on this, but didn't understand quite well.

  • 1
    I believe you need to use `%%` where the `%` is not intended to be interpreted as a string formatter by Python. So, `.. date_format(created_at, '%%Y-%%m-%%d') ...` may work. – D-S Mar 16 '22 at 06:46
  • Oh good to know! Thanks! – aristotle29 Mar 16 '22 at 06:49

0 Answers0