You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Conversion failed when converting date and/or time from character string. #7930
@Shadowman4205 that may look ugly but, in sequelize/lib/data-types.js, you can replace the method:
DATE.prototype._stringify = function _stringify(date, options) {
date = this._applyTimezone(date, options);
// Z here means current timezone, _not_ UTC
// return date.format('YYYY-MM-DD HH:mm:ss.SSS Z');
return date.format('YYYY-MM-DD HH:mm:ss.SSS');
};
Reacted by caoyi, Carlos Eduardo Scheffer, Mauricio Payetta, Christian Saiki, Pepe, Fernando Mendoza, Laurent Debacker, Tony Brix, Sathishkumar Sethu, Tarcisio Junior and 16 more
Reacted by Pepe, Seçkin PÜLLÜ and Amitesh Ranjan
Reacted by Pepe, Ezequias Albuquerque and Hamid Mamdoohi
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
THANK YOU! I JUST TRY, but too many keys dosent work at macbook. i will
check later didnt slept 2 days.
вс, 18 февр. 2018 г. в 20:24, Ricardo Melo <[email protected]>:
The workaround I'm currently using is to use strings instead of dates for my models and then passing the ISO string instead of the date object.
// Doesn't work because new Date() is an object, not a string
MyModel.create({
imported_date: new Date()
});
// Works (if type of imported_date is STRING)
MyModel.create({
imported_date: new Date().toISOString()
});
For an actual solution, maybe another data type can be added to avoid adding the timezone? DATE_NO_TIMEZONE?
Reacted by Miro, Terje Otto Tobiassen, Brandon Thaler, Andres and Tenodec
What do you all think about sending a pull request with some fix for this situation? I don't know how the devs are working properly to treat this mismatch logics between different RDMSs, so I don't feel confident enough to pull request it.
Had the same problem with mssql and found that casting to DATETIMEOFFSET worked for me in my where clause, without removing timezone serialization in DATE _stringify prototype :
Sequelize.cast(dateObj, 'DATETIMEOFFSET')
Don't know how to get Sequelize handle this directly...
Reacted by szuttenbach, Tilak Singh and Adam Moisa
This is more to note for future reference, then request a fix.
My scenario is with mssql dialect. Sequelize: [email protected]. MS SQL 2014 and 2017.
The database was not generated by Sequelize and I cannot change the data type of the column from datetime to datetimeoffset.
In the example Sequelize is generating the following string for a date. Which cannot be explicitly converted by mssql to datetime.
select * from stock
-- stockTSCreate is datetime
WHERE stockTSCreated > N'2022-04-20 16:09:54.000 +00:00';
Conversion failed when converting date and/or time from character string.
The workaround to Sequelize.cast(lastUpdated, 'DATETIMEOFFSET') works just fine.
Up to now, this problem has existed for at least 3 years, and the current version 6.21 has not been repaired. If your database has a date type primary key, if you use sequelize Save() method,although you modify the _stringify () method, but it is not affected. It still throws you type conversion errors. Perhaps the best way is to directly change your model Sequelize.DATE to Sequelize.STRING()
dialect: mssql
sequelize version: 6.21
database data value: 2022-04-20 16:09:54.000
As indicated above, DataTypes.DATE is mapped to datetimeoffset, not datetime nor datetime2. If you need a DataType that maps to datetime or datetime2, here are the relevant issues:
While we do plan on supporting datetime2, we are not currently planning on adding support for mssql's datetime data type. This will need to be handled by writing a custom data types or extending an existing one (Sequelize 7)
These are the relevant issues, please head to these instead
Activity
cladjules commentedon Aug 14, 2017
@Shadowman4205 that may look ugly but, in sequelize/lib/data-types.js, you can replace the method:
stale commentedon Sep 22, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
epozsh commentedon Sep 25, 2017
@cladjules Thank you for this solution for now.
carlosscheffer commentedon Nov 3, 2017
I'm facing the same problem, however it's within the ambit of comparison:
WHERE [PedidoVenda].[DATA_ALTERACAO] > N'2017-11-01 11:14:03.267 +00:00'thats returns me
jnreynoso commentedon Jan 29, 2018
+1
andersao commentedon Feb 7, 2018
+1
balazsnemeth commentedon Feb 8, 2018
+1 -> Same issue with dateformat "2018-02-08T05:00:00.000Z" on version 4.32.6
spyter commentedon Feb 12, 2018
+1
The date value below is a result of setting processed = new Date();
UPDATE [dbo].[Alert] SET [Processed]=N'2018-02-12 20:31:19.470 +00:00' OUTPUT INSERTED.* WHERE [Id] = N'27961F66-E5A5-47FE-8B89-0DA140D2C1EC'
RicardoDMelo commentedon Feb 18, 2018
+1
Vovka19 commentedon Feb 18, 2018
balazsnemeth commentedon Feb 27, 2018
Any news on this?
henryjw commentedon Mar 23, 2018
The workaround I'm currently using is to use strings instead of dates for my models and then passing the ISO string instead of the date object.
For an actual solution, maybe another data type can be added to avoid adding the timezone?
DATE_NO_TIMEZONE?7 remaining items
v1d3rm3 commentedon Dec 21, 2018
No news?
juniortarcisio commentedon Dec 21, 2018
What do you all think about sending a pull request with some fix for this situation? I don't know how the devs are working properly to treat this mismatch logics between different RDMSs, so I don't feel confident enough to pull request it.
molaux commentedon Apr 17, 2019
Had the same problem with mssql and found that casting to
DATETIMEOFFSETworked for me in my where clause, without removing timezone serialization in DATE _stringify prototype :Don't know how to get Sequelize handle this directly...
epozsh commentedon May 4, 2020
So this is issue still on!
Any news for regarding this?
randomaxess commentedon Feb 24, 2022
This is still an issue.
Naim-Bijapure commentedon Mar 23, 2022
still an issue
ephys commentedon Mar 23, 2022
This issue has been open for a long time and I believe it's because we don't have enough information to properly understand it.
According to the documentation,
DataTypes.DATEis supposed to beDATE WITH TIMEZONE(or equivalent).To resolve this issue we need to know:
Providing a SSCCE that reproduces this issue would also greatly help getting this resolved.
byron70 commentedon Apr 22, 2022
This is more to note for future reference, then request a fix.
My scenario is with mssql dialect. Sequelize: [email protected]. MS SQL 2014 and 2017.
The database was not generated by Sequelize and I cannot change the data type of the column from
datetimetodatetimeoffset.In the example Sequelize is generating the following string for a date. Which cannot be explicitly converted by mssql to
datetime.The workaround to
Sequelize.cast(lastUpdated, 'DATETIMEOFFSET')works just fine.ephys commentedon Apr 22, 2022
@byron70 Then I have some good news. Adding support for
datetime2(without offset) for mssql is somewhere on my backlog #14295qq578023708 commentedon Jun 18, 2022
Up to now, this problem has existed for at least 3 years, and the current version 6.21 has not been repaired. If your database has a date type primary key, if you use sequelize Save() method,although you modify the _stringify () method, but it is not affected. It still throws you type conversion errors. Perhaps the best way is to directly change your model Sequelize.DATE to Sequelize.STRING()
dialect: mssql
sequelize version: 6.21
database data value: 2022-04-20 16:09:54.000
Lancer92 commentedon Jan 20, 2023
Still not works on Windows with mssql 2019
sequalize version: 6.28.0
column type: datetime
DATA_TYPE: DATE
ephys commentedon Jan 20, 2023
As indicated above, DataTypes.DATE is mapped to
datetimeoffset, notdatetimenordatetime2. If you need a DataType that maps todatetimeordatetime2, here are the relevant issues:DataTypes.DATETIME, in whichDataTypes.DATETIME.PLAINmaps todatetime2: [looking for feedback] Reworking temporal DataTypes #14295DataTypes.DATE.PLAIN, which also maps todatetime2: feat: add DataTypes.DATE.PLAIN #15565While we do plan on supporting
datetime2, we are not currently planning on adding support for mssql'sdatetimedata type. This will need to be handled by writing a custom data types or extending an existing one (Sequelize 7)These are the relevant issues, please head to these instead