# Timestamp to SQL Server in Node Red

**URL:** <https://discourse.nodered.org/t/timestamp-to-sql-server-in-node-red/81813>\
**Category:** Dashboard\
**Tags:** database\
**Created:** [6 October 2023 02:09 UTC](https://discourse.nodered.org/t/timestamp-to-sql-server-in-node-red/81813 "2023-10-06T02:09:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boy\_co\_don](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@Boy\_co\_don](https://discourse.nodered.org/u/Boy_co_don)\
**Post date:** [6 October 2023 02:09 UTC](https://discourse.nodered.org/t/timestamp-to-sql-server-in-node-red/81813/1 "2023-10-06T02:09:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 October 2023 05:39 UTC](https://discourse.nodered.org/t/timestamp-to-sql-server-in-node-red/81813/2 "2023-10-06T05:39:27Z")

</div>

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

> [@Boy\_co\_don](#):
>
> but timestamp is stored in sql with number format.  
> How can I convert it into datTime format i

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

```auto
[{"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()`

 ![chrome_screenshot_1696570464126](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/7685b5998baa49fd29f096bcfaed105bf2fdcb1b.png)

You coud also use the [Date() method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#examples) in a function node

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 October 2023 05:47 UTC](https://discourse.nodered.org/t/timestamp-to-sql-server-in-node-red/81813/3 "2023-10-06T05:47:38Z")

</div>

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](https://flows.nodered.org/node/node-red-contrib-mssql-plus)

Here is an example of what I mean: [Can't upload some values to MSSQL - #15 by Steve-Mcl](https://discourse.nodered.org/t/cant-upload-some-values-to-mssql/53931/15)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 November 2023 05:48 UTC](https://discourse.nodered.org/t/timestamp-to-sql-server-in-node-red/81813/4 "2023-11-05T05:48:13Z")

</div>

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