Node mysql inserting the current date
The mysql node docs give an example on how to run away and do neat things. I cannot figure out how to insert the current time using this approach.
var post = {id: 1, createdDate: 'NOW()'};
var query = connection.query('INSERT INTO posts SET ?', post, function(err, result) {
});
// Error: ER_TRUNCATED_WRONG_VALUE: Incorrect datetime value: 'NOW()' for column 'createdDate' at row 1
+3
source to share
1 answer
A simple workaround if you don't want to use custom formats would be to create a server side date with new Date()
:
var post = {
id: 1,
createdDate: new Date()
};
var query = connection.query('INSERT INTO posts SET ?', post, function(err, result) {});
But keep in mind that you might have a little latency due to server / network latency.
+1
source to share