简体   繁体   中英

nodejs mssql date query returns long format date instead of default string literal

I have a sql query for a column which takes the value of 'date' when I run SELECT * FROM ConferenceMetaData I get '2018-09-05'. The '2018-09-05' comes from the DB, but when I run the same SQL code in NodeJS the RecordSet returns "Tue Sep 04 2018 17:00:00 GMT-0700 (Pacific Daylight Time)".

Thus the question is: why am I not getting "2018-09-05" from running SELECT * FROM ConferenceMetaData in NodeJS?

nodeJS is interpreting the date returned from SQL Server as UTC date/time (2018-09-05 00:00:00) and it is converting that the current timezone, which assuming is PST/PDT would be 4th Sept @ 5pm.

So, the answer is that you ARE getting 2018-09-05 00:00:00 UTC, only it is being expressed in PST/PDT timezone. Try looking at the UTC value of the date object in nodeJS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM