Timestamp to SQL Server in Node Red

Dear Expert
I'm using Node ned to connect SQL server.
The connection was OK.
I want to insert timestamp from node red into SQL, but timestamp is stored in sql with number format.
How can I convert it into datTime format in order to storing in sql.
Best

With th confusing and lack of info you supply i can only assume.

The dashboard date picker outputs a numerical unix timestamp in milliseconds, what dashboard node are you using?

You can use moments in a change node to format a ISO timestamp.

Heres is an example of both

[{"id":"ac3113ae87d7d142","type":"ui_date_picker","z":"c31640d81bf733c7","name":"","label":"date","group":"8b5cde76.edd58","order":8,"width":0,"height":0,"passthru":true,"topic":"topic","topicType":"msg","className":"","x":130,"y":260,"wires":[["57df9b054bd0e252"]]},{"id":"57df9b054bd0e252","type":"debug","z":"c31640d81bf733c7","name":"debug 345","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":350,"y":260,"wires":[]},{"id":"713f148e2b705a4a","type":"change","z":"c31640d81bf733c7","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number($moment($$.payload).format(\"x\"))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":320,"wires":[["57df9b054bd0e252"]]},{"id":"357d48db7b173715","type":"inject","z":"c31640d81bf733c7","name":"2023-10-13T00:00:00.000Z","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2023-10-13T00:00:00.000Z","payloadType":"str","x":190,"y":320,"wires":[["713f148e2b705a4a"]]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

Or from timestamp numerical to ISO format
$moment($$.payload).format()

You coud also use the Date() method in a function node

Getting the correct format for transmitting a timestamp to SQL server from JavaScript can be tricky.

The least difficult (and safest) way is to use parameters and specify the correct type.

This is all done graphically in the editor if you are using node-red- contrib-mssql-plus

Here is an example of what I mean: Can't upload some values to MSSQL - #15 by Steve-Mcl

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.