diff --git a/commcare_export/writers.py b/commcare_export/writers.py index 8e742fbf..2a13c5c2 100644 --- a/commcare_export/writers.py +++ b/commcare_export/writers.py @@ -357,7 +357,10 @@ def best_type_for(self, val): if isinstance(val, bool): return sqlalchemy.Boolean() elif isinstance(val, datetime.datetime): - return sqlalchemy.DateTime() + if self.is_mssql: + return sqlalchemy.dialects.mssql.DATETIME2() + else: + return sqlalchemy.DateTime() elif isinstance(val, datetime.date): return sqlalchemy.Date() diff --git a/tests/test_writers.py b/tests/test_writers.py index a574c86c..fddcce59 100644 --- a/tests/test_writers.py +++ b/tests/test_writers.py @@ -281,9 +281,8 @@ def test_change_type(self, writer): expected['bazzle']['c'] = '0' if 'pyodbc' in writer.connection.engine.driver: expected['bazzle']['c'] = '0' - # couldn't figure out how to make SQL Server convert date to ISO8601 - # see https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-2017#date-and-time-styles - expected['bazzle']['e'] = 'May 1 2014 11:16AM' + # MSSQL includes fractional seconds in returned value. + expected['bazzle']['e'] = '2014-05-01 11:16:45.0000000' for id, row in result.items(): assert id in expected