Node-oracledb, Date column in select result on app.js side, appears 2 days less than date columns in Oracle database.
select appointment_date from appointments where id = 1;
result on Oracle:
2024-08-07T10:10:08.000Z
on Node.js app I get this output:
2024-08-06T10:10:08.000Z
I added these lines at the top of the code document, but it doesn’t work:
process.env.TZ = 'UTC'; process.env.ORA_SDTZ = 'UTC';
process.env.TZ = 'UTC';
process.env.ORA_SDTZ = 'UTC';
const oracledb = require('oracledb');
oracledb.getConnection(dbConfig)
.then(async function (connection) {
return connection.execute(
'select appointment_date from appointments where id = 1',
[], // no binds
{
outFormat: oracledb.OBJECT
}
)
.then(function (result) {
console.log(result.rows);
connection.close();
})
.catch(function (error) {
connection.close();
});
})
.catch(function (error) {
});
References I tried to solve the problem:
node-oracledb Documentation for the Oracle Database Node.js Add-on
Fetching Dates and Timestamps – https://node-oracledb.readthedocs.io/en/latest/user_guide/sql_execution.html
m7mdbook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.