I am trying to populate Pandas Dataframe into empty MS Access 2016 table via pyodbc. I get the following error message when I try to insert Dataframes into Access: pyodbc.dataerror: ('22008', [ODBC Microsoft Access Driver]Datetime field overflow.
Research showed that MS Access Date/Time datatypes correspond to ODBC SQL_TIMESTAMP datatypes.
I tried the following to convert datetime64[ns] to SQL_TIMESTAMP:
import datetime
cursor.execute("INSERT sql statement...VALUES(?)", datetime.datetime(order_date))
However, I get this error: TypeError: an integer is required (got type Timestamp).
What do I need to do in order to successfully populate Pandas/Numpy's datetime64[ns] values into Access tables? Do I need to convert them into SQL_TIMESTAMP and how?
EDIT: I tried running Gord Thompson's solution below and I am running into this error:
import datetime
dt = dt64_to_datetime(dt_ns)
>> AttributeError:'datetime' has no attribute 'utcfromtimestamp'
What is the reason behind this error? (Tested on pyodbc 4.0.17, Python 3.6.2, MS Access 2016)
As illustrated in this excellent answer, you'll probably need to convert the
numpy.datetime64
values to Pythondatetime
values, perhaps like this:Example usage:
(Tested with pyodbc 4.0.21 and Access 2010.)