I'm using BCP and python to import a .CSV
file into a SQL Server table. The .CSV
file has a column containing date time data and my table also has a corresponding datetime2 column. The problem is that the date in the .CSV
file is of format:
2017-01-13T06:02:14Z
which throws an error while running BCP command. My BCP command looks like this:
bcp mydb.dbo.mytable in {0} -R -e errorfile -c -S mysqlserver.com -U myuser -P 'mypassword'
and the error is:
Invalid character value for cast specification @# 2017-01-13T06:02:14Z
If I change the date in my .CSV
file to '2017-01-13 12:33:49', BCP works fine. The error is because BCP tool uses ODBC bulk copy API. Therefore, to import date values into SQL Server, bcp uses the ODBC date format (yyyy-mm-dd hh:mm:ss[.f...]).
What is the way around to fix this issue?
Is there way out to change the date format inside of CSV file itself from 2017-01-13T06:02:14Z to yyyy-mm-dd hh:mm:ss?