问题
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