question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mssql "date" type get the value as the previous day

See original GitHub issue

Issue 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): image

The result from sequelize: image

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

https://github.com/sequelize/sequelize/issues/10231

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
papbcommented, Oct 22, 2019

This look like a timezone issue, have you investigated your DB and sequelize’s timezone settings?

0reactions
github-actions[bot]commented, Nov 6, 2021

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. 🙂

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found