I have a SQL query which contains date formatting on one of the columns as shown below:
%Y-%m-%d %h:%m:%s 
Here %d and %s are creating problem since they are used for formatting in Python just like C.
If this is a format string (used on the LHS of a %), then use %% to have a format that "expands" to a single %.  In your case that would be %%Y-%%m-%%d %%h:%%m:%%s
How do I use %s and %d as a string literal rather than formatter in Python?