sql server - How to update datetime field in MSSQL using python pyodbc module -


i trying update db table using convert(datetime,'19-01-16 11:34:09 pm',5), when pass string insert db table i'm getting data type conversion error.

conversion failed when converting date and/or time character string.

insert run (runid, startdate)  values ('19012016',"convert(datetime,'19-01-16 11:34:09 pm',5)") 

you getting error because passing treating string value. instead:

insert run(runid, startdate)      values ('19012016', convert(datetime, '19-01-16 11:34:09 pm', 5)) 

that is, had many quotes. in python, typically written as:

"""insert run(runid, startdate)      values ('19012016', convert(datetime, '19-01-16 11:34:09 pm', 5))""" 

if want insert values:

"""insert run(runid, startdate)      values ('{0}', convert(datetime, '{1}', 5))""".format("19012016", "19-01-16 11:34:09 pm") 

i suggest use more common format such yyyy-mm-dd hh:mm:ss, if have choice of date representation.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -