I have a datetime field in a MySQL database table on Planetscale. I want to return the datetime value after some time has been subtracted from it using the DATE_SUB function. This works in the database console on Planetscale’s website but is not working from my node js server request.
Server code:
const mysql = require('mysql2');
mysql.query('SELECT DATE_SUB(log_time,INTERVAL 4 HOUR) AS time FROM time_table;',[], function(err, records){
if (err) {
console.log(err);
}
else {
console.log(records);
}
})
And this is my table:
CREATE TABLE time_table (
log_time DATETIME
);
But is not subtracting the 4 hours as I am expecting and as it does on the db console on Planetscale’s website. Is this an issue with Planetscale, MySQL, MySQL2, node js, or something else? Thanks.