Eric Shreve
Eric Shreve

Reputation: 139

Error using %s for String Formatting in MySQL Query with Python

The following line is from a query that I keep getting an error on. When I change the %s to 00 it works just fine. How do I keep the formatting to have the actual seconds:

from_unixtime(el.DeviceTimeStamp/1000, '%Y-%m-%d %H:%i:%s') as 'Entry_Timestamp'```

Upvotes: 0

Views: 87

Answers (2)

Eric Shreve
Eric Shreve

Reputation: 139

On a complete lark I changed '%s' to be '%S' in my query and now it works fine.

Upvotes: 0

ScaisEdge
ScaisEdge

Reputation: 133400

I'm not in python but%s is used for passing param so Try escaping the % using %%

  from_unixtime(el.DeviceTimeStamp/1000, '%%Y-%%m-%%d %%H:%%i:%%s') as 'Entry_Timestamp'```

or

  from_unixtime(el.DeviceTimeStamp/1000, '%Y-%m-%d %H:%i:%%s') as 'Entry_Timestamp'```

Upvotes: 2

Related Questions