Coincidentally I ran into this issue last week. From what I could gather
the MS SQL data type can accept values with no more than millisecond
precision. This is true using parameterized statements through adodbapi and
also T-SQL and implicit conversion from char to datetime. The type accepts
up to seven places (nano seconds).
If you don’t mind losing some precision you can do something like this:
import datetime
import adodbapi
class MyTimeconverter(adodbapi.pythonDateTimeConverter):
def DateObjectToIsoFormatString(self, obj):
'''
Round microsecond part of datetime object to three decimal places.
'''
s = super(adodbapi.pythonDateTimeConverter,
self).DateObjectToIsoFormatString(obj)
try:
dt, micros = s.rsplit('.', 1)
except ValueError:
return s
micros = str(round(float('.' + micros), 3))[1:5]
return dt + micros
# Bind datetime.datetime parameters as string
adodbapi.typeMap[datetime.datetime] = adodbapi.adBSTR# Patch on our
datetime converter
adodbapi.adodbapi.dateconverter = MyTimeconverter()
Or maybe you can use datetime2.
—Max III
_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32