DateTime conversion failed with sequelise inserting a SQL Server record

人盡茶涼 提交于 2019-12-25 05:43:08

问题


When adding a new record into my database I get the error:

Conversion failed when converting date and/or time from character string

The datetime it tries to insert is:

2015-10-05 21:43:57.000 +00:00

It seems that Sequelise also inserts the timezone.

I tried setting the "timezone" to an empty string but this didn't help.

How can I insert a valid SQL Server DATETIME with sequelize?

Model:

    RegDate : {
       type : Tedious.TYPES.DateTime,
       defaultValue: Sequelize.NOW
    }

回答1:


Change the Column data type in the DB from DateTime to DateTime2

-- This will fail
begin tran
CREATE TABLE #Temp1 ( CTECol datetime );
insert into #Temp1 select '2015-10-05 21:43:57.000 +00:00'
rollback

-- This will Success
begin tran
CREATE TABLE #Temp1 ( CTECol datetime2 );
insert into #Temp1 select '2015-10-05 21:43:57.000 +00:00'
rollback


来源:https://stackoverflow.com/questions/32958525/datetime-conversion-failed-with-sequelise-inserting-a-sql-server-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!