How to insert a datatime object using pymssql? I know that a SQL Server table expects a datetime object, say, at position 3. I tried all three of them:
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())")
and every time I get the same error:
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')
I looked through a little documentation and searched repeatedly.
source share