I am currently using version 6.3.1 of node mssql. My query involves multiple columns that are of type date. When querying in node mssql, the output for all Date columns is in this format: 2020-10-20T00:00:00.000Z However, when I execute the same query in Azure Data Studio, I get: 2020-10-20
The issue arises when I need to update the database as I encounter an error using the YYYY-MM-DD format. Is there a method to update the database without having to manually check each field if it's a date and then append "T00:00:00.000Z" to it?
Current code snippet:
// Executed at server startup
const sql = require('mssql')
const poolPromise = sql.connect({
server: process.env.SQL_SERVER,
user: process.env.SQL_USER,
password: process.env.SQL_PASSWORD,
database: process.env.SQL_DATABASE
})
// Executed during query operation
async function updateSqlRecord(fields) {
// Adding fields below for demonstration
let fields = {id: 1, name: 'test', date: '2020-10-12' }
let database = process.env.SQL_DATABASE
let table = 'Test'
let querystring = `UPDATE [${database}].[dbo].[${table}] SET `
Object.entries(fields).forEach(field => {
const [key, value] = field;
querystring += `${key} = '${value}', `
});
querystring = querystring.slice(0, -2)
querystring += ` WHERE projektNr = ${fields.projektNr}`
try {
let pool = await poolPromise
let result = await pool.request()
// .input('projektNr', sql.Int, value)
.query(querystring)
console.log(result)
return result.rowsAffected
} catch (err) {
console.log('SQL request Error',err)
}
}