mssql "date" type get the value as the previous day
See original GitHub issueIssue Description
For mssql “date” type, retrieves the date as 1 day less than the stored value.
What are you doing?
In db the value is “2019-10-30” but the returned value is “2019-10-29”
The result from db (using the sql query generated by sequelize):
The result from sequelize:
This is the js code
const userProfile = await UserProfile.findByPk(session.userProfileId);
logger.info(`but the birthday for userprofile ${userProfile.id} is ${userProfile.birthDate}`);
What do you expect to happen?
it should return “2019-10-30”
What is actually happening?
it returns “2019-10-29”
Environment
- Sequelize version: 5.12.2
- Node.js version: 11.13.0
- Operating System: MacOS
- TypeScript version: 3.1.6
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s): mssql
- I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don’t know how to start, I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Related issues
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
SQL statement to select all rows from previous day
To get the "today" value in SQL: convert(date, GETDATE()). To get "yesterday": DATEADD(day, -1, convert(date, GETDATE())).
Read more >Derive the Previous Day in SQL Server - Microsoft Q&A
8 Answers · DECLARE @var DATETIME = GETDATE(); · SELECT @var AS [Before] ·, FORMAT(DATEADD(DAY,-1,@var),'yyyy-MM-dd 00:00:00.000') AS [After];.
Read more >SQL Server GETDATE () function and its use cases
DATEADD function helps us to get current, future, or past date-time based on the specified number to the input DateTime. Below are the...
Read more >SQL Server Datetime functions examples - DatabaseFAQs.com
Now let us see how to use it. Suppose, I have a Date data type value as 2021-12-15. We can find the last...
Read more >sql server - How to extract data between yesterday and today?
You can always find today (with no time) using SELECT CONVERT(date, GETDATE()); . So to find all of the data for yesterday, you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This look like a timezone issue, have you investigated your DB and sequelize’s timezone settings?
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the “stale” label. 🙂