tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.23k stars 465 forks source link

Issue returning wrong column typed as datatime #1497

Closed heliocj closed 1 year ago

heliocj commented 1 year ago

There is an issue when trying to return the column typed as datatime with select to a const variable typed as Date. At the database have a data like "2014-10-01 00:00:00". If I execute the select at the database that is returning the correct data, but at nodejs that is returning like "2014-01-09T22:00:00.000Z". To get the right data I have to use format function and work with columns typed as string.

Expected behaviour:

Expected data returning at the right format and value.

Actual behaviour:

The simple SQL for test: "select * from table"

Configuration:

// paste relevant config here data at the database image

data at the nodejs image image

Software versions

dhensby commented 1 year ago

I think you've made a typo, because your screenshot says 2014-01-10 00:00:00.000 but your description says 2014-10-01 00:00:00. It doesn't make much sense why there would be a jump from 1st October to 9th January.

But if it is just a 2 hour offset, that looks like a timezone issue where the timezone of your database is not the same as your application code. Have you tried using useUTC option?

heliocj commented 1 year ago

Setting the useUTC to false just made it back to work. Thank you.