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.

UTC problem and One Day Off

See original GitHub issue

Hello!

In node-mssql (6.3.1) / Tedious (6.7.0):

I’m having problems with not using utc in driver: setUTC = false. If the hour of the date is anything is between 00:00:00 - 00:0:27, than, in database, it subtracts one day (???) of the Date.

For example:

Using new Date(2021, 4, 27, 0, 0, 27) to generate the Date (2021-05-27T03:00:27.000Z) (in backend) gives me 2021-05-26 00:00:27

Using new Date(2021, 4, 27, 0, 0, 28) to generate the Date (2021-05-27T03:00:28.000Z) (in backend) gives me 2021-05-27 00:00:28

Using new Date(2021, 4, 27, 0, 0, 0) to generate the Date (2021-05-27T03:00:00.000Z) (in backend) gives me 2021-05-26 00:00:00

The code/repro:

import * as sql from "mssql";

const pool = new sql.ConnectionPool({
  user: "xxxx",
  password: "xxxxx",
  server: "xxxxx",
  database: "xxxxx",
  options: {
    enableArithAbort: true,
    useUTC: false,
    trustServerCertificate: true,
  },
});

async function start() {
  const conn = await pool.connect();

  let myDate = new Date(2021, 4, 27, 0, 0, 0);
  console.log(myDate);
  

  await conn.request().input("dt", sql.DateTime, myDate).query(`
    UPDATE example
    SET date= @dt
    WHERE id= 1;
  `);

  const res1 = await conn.query(
    "select date from example where id = 1"
  );
  console.log(res1.recordset);

  await pool.close();
}

start();

In node-mssql (7.0.0-beta.5) / Tedious (11.0.5):

All things works as expected in same code.

For example:

Using new Date(2021, 4, 27, 0, 0, 0) to generate the Date (2021-05-27T03:00:00.000Z) (in backend) gives me 2021-05-27 00:00:00


But i can’t use mssql 7.0.0-beta.5. I’m using typeorm lib, and it ins’t compatible with the mssql 7.x version.

Anyone can help me?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
arthurschreibercommented, Apr 27, 2021

We don’t generally backport fixes to old versions, because that’s a huge maintenance overhead and we’re basically just two people working on tedious right now. How do you feel about this?

A new version of node-mysql is in the works that updates to the latest version of tedious, so that might fix your issue soon? 🙇‍♂️

0reactions
v1d3rm3commented, Apr 28, 2021

@IanChokS, sorry, i think i don’t understand. Second argument refers to type of value or type of name of parameter.

What i want to say is that in older versions, the name of the parameter (first param of addParameter function - [number] 0 as any)could be a number, for example? Or always the name of the parameter was a string?

Because in older version of mssql, at least, i could pass a number as name of parameter, and it worked. This error is from it:

The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received type number (0)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is the Javascript date object always one day off?
It parses it with the GMT/UTC timezone (Sep 24 2011, 00:00 UTC) and then outputs it with a different timezone of 4 hours...
Read more >
A Complete Guide to JavaScript Dates (and why your date is ...
A Complete Guide to JavaScript Dates (and why your date is off by 1 day). #javascript. JavaScript dates are confusing. Furthermore, they might ......
Read more >
Sitecore Troubleshooting: Date Fields Off by One Day
Solution. Server time zone needs to be UTC and you may want to correct date fields that were saved when the server time...
Read more >
JavaScript Date Object and Time Zones | Fixing an "off by 1 ...
How to handle UTC and local time zone when turning a date string into a JavaScript Date object. And fixing a bug where...
Read more >
Dataverse Date only field is set 1 day off from original value
Hi there, So I am having issues with dates being retrieved by my Flow ... Dataverse Date only field is set 1 day...
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