1

Using Node + mssql, I need to get the offset for the date that is returned from SQL Server for this query:

SELECT getutcdate() AT TIME ZONE 'UTC' AT TIME ZONE 'Mountain Standard Time'

The issue is it comes out of mssql/tedious already parsed as a JavaScript Date() object, set to the time zone of the script/host machine. There is no way that I can see to tell what time zone/offset the original value is actually in.

Other tools, such as Azure Data Studio, correctly show the raw value in the table for DateTimeOffset columns, including showing the stored offset.

Output in Node:

[ { value: 2020-03-21T03:07:54.193Z } ]

Output in Azure Data Studio:

2020-03-20 21:07:22.9970000 -06:00

Code:

const sql = require('mssql');

sql.connect('mssql://sa:<password>@localhost?useUTC=false')
  .then(() => {
    const request = new sql.Request();
    request.query(query, (err, result) => {
      console.dir(result.recordset)
    });
  });
Seth
  • 1,353
  • 1
  • 8
  • 17

0 Answers0