python mysqldb 解决format_data(a, '%Y-%d-%m')的冲突
伊谢尔伦
伊谢尔伦 2017-04-17 17:36:23
0
2
895

当涉及到使用这个函数查询的时候 如何select 不动态传递参数 如何新添加参数就会报以下的错误
ValueError: unsupported format character 'Y' (0x59) at index 47

select date_format(dd,'%Y-%m-%d') a_dd from user ;这样没有问题
select date_format(dd,'%Y-%m-%d') a_dd from user where userid in %s;

ord_sta = (12,33)
cursor.execute(sql, params) 就出错误了 不晓得大家怎么解决

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
Peter_Zhu

Please use '%%Y-%%m-%%d'. When sql has %s, it will be pre-compiled. Other characters with % will be compiled, and %Y is not any kind. .

伊谢尔伦

What do you use to operate the database? ? sqlalchemy or mysql.connector??
If it is sqlalchemy, use the strftime('%Y-%m-%d') method to get the time represented by a string

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template