如何使用 pymssql 插入数据时间对象?我知道 SQL Server 表需要一个日期时间对象,假设在位置 3。我已经尝试了所有这三个:
cursor.execute("INSERT INTO MyTable VALUES(1, 'Having Trouble', datetime.datetime.now())")
cursor.execute("INSERT INTO MyTable VALUES(1, 'Having Trouble', 20130410)")
cursor.execute("INSERT INTO MyTable VALUES(1, 'Having Trouble', '20130410')")
cursor.execute("INSERT INTO MyTable VALUES(1, 'Having Trouble', GETDATE())")
我每次都得到同样的错误:
OperationalError: (241, 'Conversion failed when converting date and/or time from character string.DB-Lib error message 241, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')
我已经搜索了那里的小文档,并反复搜索。
编辑:次要问题是字段长度问题。请参阅有关已接受答案的第一条评论。