3

I have a date column in my DB. When querying it with SQLDeveloper like so

SELECT some_date as "Some date",
       cast(some_date as timestamp) at time zone 'UTC' as "Some date UTC"
FROM mytable
FETCH NEXT 1 ROWS ONLY;

I get this back
09-NOV-17 10.00.00.000000000 PM UTC

When running this code in Node:

const oracledb = require('oracledb');

const dbConfig = {
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  connectString: process.env.DB_TNSNAME,
};

oracledb.getConnection(dbConfig).then(async conn => {
  const result = await conn.execute('SELECT some_date FROM mytable FETCH NEXT 1 ROWS ONLY');
  console.log(result.rows[0][0]);
});

I get this output: 2017-11-09T21:00:00.000Z
And when converting this date to local time, for example with moment:

console.log(moment(date).format('YYYY/MM/DD HH:mm:ss'));

I get 2017/11/09 23:00:00

So basically, it seems the date I get when querying the DB through JS is 1 hour behind the date when querying through SQL developer.
I suspect this has something to do with NOV-09 being regular time (so my local time is GMT+2) and the fact that it's currently DST (my local time is GMT+3), but how do I actually fix this?

3

1 Answer 1

2

Did you try this (https://oracle.github.io/node-oracledb/doc/api.html#-16173-fetching-dates-and-timestamps)?

You can set the environment variable ORA_SDTZ before starting Node.js, for example:

$ export ORA_SDTZ='UTC'
$ node myapp.js
Sign up to request clarification or add additional context in comments.

1 Comment

For the record, I followed the 2nd option in memodba's provided link and set the client time zone within my Node.JS app: process.env.ORA_SDTZ = 'UTC'; (before connection is initialised).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.