I am trying to insert a datetime value into an MS SQL Server table using pyodbc. If I do it manually, something like:
cursor.execute("""insert into currentvalue(value1,currentdatetime) values(55,'2014-06-27 16:42:48.533')""")
I have no problem at all, but when I try to do:
currenttime = str(datetime.datetime.now()) cursor.execute("""insert into currentvalue(value1,currentdatetime) values(55,"""+ currenttime+")")
I got this error:
SQL Server Invalid syntax next to '07', which I think is the number after the date and starts the time.
Also I tried this:
currenttime = "'"+str(datetime.datetime.now())+"'"
and now this error occurs:
Conversion error while converting date and / or time from character string.
source share