Repository navigation
Description
What are you doing?
Using DATEONLY, when querying the database directly the date is '2019-06-01', but Sequelize returns '2019-05-31'. I'm in the US Central timezone, so I assume it is still treating it as a UTC date and converting it to my timezone.
It is only returning the string in 'YYYY-MM-DD' format, which is good, but it is converting it based on my local time, which is bad.
Sequelize: 5.8.5
Tedious: 6.1.1
MS SQL Server 2017
What do you expect to happen?
Return the date string as stored without converting based on local timezone.
What is actually happening?
The date string is converted to local time, which displays as the previous day. '2019-06-01' is stored in the database, but '2019-05-31' is returned by Sequelize.
I rolled back to Sequelize 4.41.2 and Tedious 3.0.1 and the same date is returned as '2019-06-01T05:00:00.000Z'. So, it seems that DATEONLY has since been fixed to only return a date string without time and timezone, but it now assumes that the stored date is in UTC and incorrectly converts it to local time.
Summary:
SQL Server DATEONLY Field Value: '2019-06-01'
Sequelize 5.8.5 returns: '2019-05-31'
Sequelize 4.41.2 returns: '2019-06-01T05:00:00.000Z'
My timezone: US Central Time (currently -5:00 with Daylight Saving Time)
Environment
Dialect:
- mysql
- postgres
- sqlite
- mssql
- any
Dialect library version: Tedious 6.1.1
Database version: MS SQL Server 2017
Sequelize version: 5.8.5
Node Version: 8.11.0
OS: Windows 10
If TypeScript related: TypeScript version: XXX
Tested with latest release: - No
- Yes, specify that version: 5.8.6
Activity
c1oud45 commentedon Aug 4, 2019
Hi, did you find any workaround for this issue?
tonyguinta commentedon Aug 21, 2019
Hi, sorry for the delay in responding.
My workaround was to roll back to Sequelize 4.41.2 and Tedious 3.0.1, which still returns a full datetime string for DATEONLY data types, but at least it returns it in the correct timezone.
dead commentedon Sep 6, 2019
sequelize/lib/dialects/mssql/data-types.js
Line 130 in 555dbe1
Changing to:
Fix this issue for me.
@papb Can you take a look in this?
I saw that others dialects uses
moment(value)from theBaseType.DATEONLYbut I saw nobody reporting problems with DATEONLYpapb commentedon Sep 6, 2019
@dead Hmm... While you're at it, can you test two other things as well?
Test 1 - Removing the extended DATEONLY class entirely (also removing here)
Test 2 - Changing parse to an string-casting function:
Thanks!
dead commentedon Sep 9, 2019
@papb
Test 1 -
It worked.Didn't workTest 2 - Didn't work, the parsed date was in invalid format.
papb commentedon Sep 9, 2019
@dead Nice! Can you submit a PR with my first suggestion?
nmeeda commentedon Jun 23, 2020
I hope is it still Open?
tonyguinta commentedon Oct 5, 2020
This is still a problem with Sequelize 6.3.5 and Tedious 9.2.1 on Node 11.3.
Server Timezone: 'UTC -5:00'
Date stored in SQL Server: '2020-10-01'
Value returned from Sequelize 6.3.5 and Tedious 9.2.1 via Postman: '2020-09-30'
Value returned from Sequelize 4.41.2 and Tedious 3.0.1 via Postman: '2020-10-01T05:00:00.000Z'
If I change my timezone to UTC and start up Node, then Sequelize 6.3.5 and Tedious 9.2.1 return '2020-10-01'. It's pretty clear that the stored date is treated as UTC and is converting it to the Node server's timezone.
I have confirmed that the change in this pull request fixes the issue, but has yet to be included in a release.
tonyguinta commentedon Oct 6, 2020
Pull request 11409 does indeed fix this issue, but it has yet to be included in a Sequelize release.
As a workaround, I've made the change directly to my installation in node_modules and used patch-package, which allows me to include the change in my source code and deploy it to my higher environments.
azterix commentedon Oct 22, 2020
If you're looking for a workaround and don't want to get in to patching the package while we await that PR making it to release, I discovered this workaround that works for me using the moment-timezone package:
Thanks to @dengue8830 for the workaround over on #11597
spearmootz commentedon Nov 12, 2020
instead of changing the dependency you can just do this
class DATEONLY extends BaseTypes.DATEONLY {
static parse(value) {
return moment.utc(value).format('YYYY-MM-DD');
}
}
so add .utc(value)
nandanv2702 commentedon Sep 13, 2021
Hey, I recently came across this issue too - using Sequelize version 6.6.5 with the workaround suggested in Pull Request 11409
github-actions commentedon Nov 10, 2021
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂