I would recommend to process rows instead of trying to change MySQL output result. This way your database will have detailed full data about the created_date. While clients (other functions, systems, projects, etc) will format the value retrieved from DB to whatever format they need. Moreover you will keep a consistent return results for dates through your system. Whatever DB query is executed your software will always expect the same format returned back.
Here is an example in ES6 also using moment.js library to simplify any date operations you will have, strongly recommend to use this library.
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'a',
database: 'signal'
});
function formatDate(date) {
return moment(date).format('YYYY-MM-DD HH:mm:ss');
}
connection.query(command, (err, rows) => {
if (err) {
throw err;
}
rows = rows.map(row => ({
...row,
created_date: formatDate(row.created_date)
}));
console.log(rows);
});
update or in ES5
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'a',
database: 'signal'
});
function formatDate(date) {
return moment(date).format('YYYY-MM-DD HH:mm:ss');
}
connection.query(command, function(err, rows) {
if (err) {
throw err;
}
rows = rows.map(function(row) {
return Object.assign({}, row, { created_date: formatDate(row.created_date) });
});
console.log(rows);
});