I need to enter the current date and time via Node-RED into a SQL SERVER database, but it gives an error message.
I'm using the pallete: node-red-contrib-moment
I use the -3 hour time zone and then send it to a function. Inside the function, I do the insert for the bank and it shows an error, the code below the function follows.
var year = msg.payload.substring(0, 4)
var month = msg.payload.substring(5, 7)
var day = msg.payload.substring(8, 10)
var hours = msg.payload.substring(11, 13)
var minutes = msg.payload.substring(14, 16)
var seconds = msg.payload.substring(17, 19)
var date = + year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds
msg.topic = "insert into Valores (TesteDataString) values (" + date + ")"
return msg;
The database field is datetime, I also tried varchar, but it has the same error
I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
I've already performed some tests and I'm managing to insert the date and time into the database. Thank you very much for your help, I have been working on it for some time.
I use Node-RED to collect data from a PLC, where I use Grafana to display this data. Saving the date and time in this UTC format also solved a problem I had with Grafana when displaying the date and time, thank you very much for your help