# Convert datetime with moment

**URL:** <https://discourse.nodered.org/t/convert-datetime-with-moment/13130>\
**Category:** General\
**Created:** [10 July 2019 20:39 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130 "2019-07-10T20:39:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_D](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Vincent\_D](https://discourse.nodered.org/u/Vincent_D)\
**Post date:** [10 July 2019 20:39 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/1 "2019-07-10T20:39:34Z")

</div>

Hi. I hope I can get some help from you guys.  
I'm having a little trouble getting the date and time the way I want.  
I have node red read temp and time from a mysql database, in the database the input of time is like this "2019-07-10 21:39:08" and out of node reds mysql it comes like this "2019-07-10T19:39:08.000Z"

I have added the moment node, but its only the date that is right, the time shows 00:00:00...  
So its like this out of the Date/Time formatter: "10-07-2019 00:00:00"  
What am I doing wrong?

 ![Skjermbilde](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0e138dfe8ebb627791c11a26148b1d26c877f970.jpeg)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 July 2019 21:09 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/2 "2019-07-10T21:09:40Z")

</div>

That should work. I will test. Can you double-check that you are actually getting the date/time you think you are? Use a debug node to output the value that you are feeding into the moment node.

---

<div class="post-metadata">

**Author:** ![Vincent\_D](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Vincent\_D](https://discourse.nodered.org/u/Vincent_D)\
**Post date:** [10 July 2019 21:16 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/3 "2019-07-10T21:16:09Z")

</div>

Yes I've checked with debug nodes. Out from the db is "2019-07-10T19:39:08.000Z"  
and out from the moment node is "10-07-2019 00:00:00" 🥺

Thanks for helping 😀

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 July 2019 21:16 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/4 "2019-07-10T21:16:20Z")

</div>

> [@Vincent\_D](#):
>
> 2019-07-10T19:39:08.000Z

Nope. I've tried this and it works fine.

```auto
[{"id":"f086bf6d.7f374","type":"inject","z":"63281c77.40a064","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":440,"y":180,"wires":[["737aadca.38ea14","491774.d5a0188c"]]},{"id":"672a6b0e.c8ebf4","type":"debug","z":"63281c77.40a064","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":850,"y":180,"wires":[]},{"id":"737aadca.38ea14","type":"moment","z":"63281c77.40a064","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Europe/Oslo","adjAmount":0,"adjType":"days","adjDir":"add","format":"DD-MM-YYYY HH:mm:ss","locale":"en_US","output":"payload","outputType":"msg","outTz":"Europe/Oslo","x":640,"y":180,"wires":[["672a6b0e.c8ebf4"]]},{"id":"491774.d5a0188c","type":"debug","z":"63281c77.40a064","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":140,"wires":[]},{"id":"1cb7c5e7.9ff48a","type":"inject","z":"63281c77.40a064","name":"","topic":"","payload":"2019-07-10T19:39:08.000Z","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":430,"y":220,"wires":[["491774.d5a0188c","737aadca.38ea14"]]}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/210f2de681c4d0fb0c06f2e2f53b5e21263bca64.png)

Settings the same as yours.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bdbe651d63bafed3b6bb5406340e3c959a1018aa.png)

Can you show the output from the debug node?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 July 2019 21:21 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/5 "2019-07-10T21:21:41Z")

</div>

To be doubly sure, I used a function node to make the payload an array as shown in your settings.

```auto
[{"id":"672a6b0e.c8ebf4","type":"debug","z":"63281c77.40a064","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":850,"y":180,"wires":[]},{"id":"737aadca.38ea14","type":"moment","z":"63281c77.40a064","name":"","topic":"","input":"payload[0]","inputType":"msg","inTz":"Europe/Oslo","adjAmount":0,"adjType":"days","adjDir":"add","format":"DD-MM-YYYY HH:mm:ss","locale":"en_US","output":"payload[0]","outputType":"msg","outTz":"Europe/Oslo","x":640,"y":180,"wires":[["672a6b0e.c8ebf4"]]},{"id":"491774.d5a0188c","type":"debug","z":"63281c77.40a064","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":140,"wires":[]},{"id":"1cb7c5e7.9ff48a","type":"inject","z":"63281c77.40a064","name":"","topic":"","payload":"2019-07-10T19:39:08.000Z","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":180,"wires":[["59d04603.cdee98"]]},{"id":"59d04603.cdee98","type":"function","z":"63281c77.40a064","name":"","func":"msg.payload = ['2019-07-10T19:39:08.000Z']\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":180,"wires":[["737aadca.38ea14","491774.d5a0188c"]]}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9a153f6a7bd7af0c360bef0af64f61d283038e23.png)

Output as expected.

Can you also check what version of moment you have installed?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/caf9c9aba3c37a1acc1818204f4438c3e063a901.png)

---

<div class="post-metadata">

**Author:** ![Vincent\_D](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Vincent\_D](https://discourse.nodered.org/u/Vincent_D)\
**Post date:** [10 July 2019 21:23 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/6 "2019-07-10T21:23:41Z")

</div>

I also have 3.0.3. Strange...

 ![Skjermbilde2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/45875a66c63b30ab43bf81ba8edde22ccefbf860.jpeg)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 July 2019 21:25 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/7 "2019-07-10T21:25:01Z")

</div>

Not strange maybe. The value is actually on `msg.payload[0].TID` not on `msg.payload[0]`

You can hover over the value and then copy the path using the 1st of the 2 icons to the right:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7fc95814a6813de0bebefc74440a27fa8f2e3fdf.png)

---

<div class="post-metadata">

**Author:** ![Vincent\_D](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Vincent\_D](https://discourse.nodered.org/u/Vincent_D)\
**Post date:** [10 July 2019 21:30 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/8 "2019-07-10T21:30:20Z")

</div>

Ok and paste in where? Little confused right now. But thanks alot for quick replys!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 July 2019 21:33 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/9 "2019-07-10T21:33:55Z")

</div>

In the "Input from" field in the moment node. You have `payload[0]`, You need `payload[0].TID`.

---

<div class="post-metadata">

**Author:** ![Vincent\_D](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Vincent\_D](https://discourse.nodered.org/u/Vincent_D)\
**Post date:** [10 July 2019 21:35 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/10 "2019-07-10T21:35:53Z")

</div>

It worked! Thanks alot. You saved the night for me 🙂

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 July 2019 21:37 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/11 "2019-07-10T21:37:34Z")

</div>

Yes, you need to always check those references carefully. That's why Nick put in those buttons - to help you get the right path, just expand the output then click the button next to the entry you need to capture. The 2nd button copies the value, the 1st copies the property path.

---

<div class="post-metadata">

**Author:** ![Vincent\_D](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Vincent\_D](https://discourse.nodered.org/u/Vincent_D)\
**Post date:** [10 July 2019 21:39 UTC](https://discourse.nodered.org/t/convert-datetime-with-moment/13130/12 "2019-07-10T21:39:35Z")

</div>

Ok I will remember that. This is my 4th day with python, mysql and node red so its a lot to take in 😁

Thanks again!
