Recently I started working with SQL databases and I have had problems storing date type columns in my tables. Basically what happens when I try to store a variable in the format yyyy-mm-dd
, for example 2016-12-23
, something happens and what goes into the table is 0000-00-00
. I tried to change the type of the variable from date to text and the stored value was 1981
, result of subtraction 2016 - 12 - 23 = 1981
. Has anyone ever had this problem or know how to solve it? I'm writing my project on node using the NPM MySQL module.
var temp = "1994-03-09";
newStaticQuery = {
sql: 'INSERT INTO SaudeParamEstaticos (idPaciente, data, steps) VALUES (${id}, ${temp}, ${activity[property][0].value})',
timeout: 10000
}
connection.query(newStaticQuery, function(err, rows, fields) {
console.log(err);
console.log(rows);
});
Here is a simpler example of my problem, following the code below, the date is entered correctly in the table, however when trying to put it in a temporary variable as in the case above the problem happens.
newStaticQuery = {
sql: 'INSERT INTO SaudeParamEstaticos (idPaciente, data, steps) VALUES (${id}, '1994-03-09', ${activity[property][0].value})',
timeout: 10000
}
connection.query(newStaticQuery, function(err, rows, fields) {
console.log(err);
console.log(rows);
});
Would it be some javascript syntax question?