1
I recently started working with SQL databases and have had problems storing date 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 gives age and what enters the table is 0000-00-00
. I tried to change the type of the date variable to text and the stored value was 1981
, subtraction 2016 - 12 - 23 = 1981
. Has anyone ever had this problem or know how to solve it? I am writing my project in Node using the Mysql NPM 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 simple example of my problem, following the code below, the date is entered correctly in the table but when trying to put it in a temporary variable as in the above case 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);
});
It would be a question of javascript syntax?
I just read the Handbook on how to NOT ask stackoverflow questions and I wanted to thank you for the constructive comments to my question which is my first on this site as well as the patience with all the "atrocities" I committed in my beginner’s innocence. Thank you stackoverflow community for the absence of negativity.
– Matheus Bafutto