【发布时间】:2016-04-07 07:26:28
【问题描述】:
我正在尝试使用日期作为变量进行相当简单的 SELECT。但我总是最终收到数据类型错误:
today = datetime.datetime.date(datetime.datetime.now())
cur.execute('select nom from agenda,taverniers where agenda.id_t = taverniers.id_t and agenda.thedate = "%s"') %(today)
抛出异常:
moncal.py:61: Warning: Incorrect date value: '%s' for column 'thedate' at row 1
cur.execute('select nom from agenda,taverniers where agenda.id_t = taverniers.id_t and agenda.thedate = "%s"') %(today)
(...)
TypeError: unsupported operand type(s) for %: 'long' and 'datetime.date'`
我的数据库有数据:
mysql> select * from agenda
-> ;
+------+------+------------+
| id_t | id_c | thedate |
+------+------+------------+
| 3 | 5 | 2015-12-12 |
| 1 | 6 | 2015-12-24 |
+------+------+------------+
有什么想法吗?谢谢。
【问题讨论】:
标签: python datetime mysql-python sqldatatypes