SmithaShivakumar SmithaShivakumar - 10 months ago 55
MySQL Question

TypeError: not enough arguments for format string - Python SQL connection while using %Y-%m

with engine.connect() as con:

rs = con.execute("""
SELECT datediff(STR_TO_DATE(CONCAT(year,'-',month,'-',day), '%Y-%m-%d') , current_date())
from TABLE
WHERE datediff(STR_TO_DATE(CONCAT(year,'-',month,'-',day), '%Y-%m-%d') , current_date()) < 900
group by STR_TO_DATE(CONCAT(year,'-',month,'-',day), '%Y-%m-%d');

I feel the compiler is getting confused with '%Y-%m-%d', I might be wrong. Could someone help me on how to avoid this "Type Error:not enough arguments for format string"?

Thanks in advance!!

Answer Source

It sees your % signs and thinks you want to format the string. I believe you should be able to replace them with %% to indicate that you want the character, not a format substitution.