# Converting DateTime to dd/mm/yyyy hh:mm

**URL:** <https://discourse.nodered.org/t/converting-datetime-to-dd-mm-yyyy-hh-mm/36012>\
**Category:** General\
**Created:** [16 November 2020 15:33 UTC](https://discourse.nodered.org/t/converting-datetime-to-dd-mm-yyyy-hh-mm/36012 "2020-11-16T15:33:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aa123](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@aa123](https://discourse.nodered.org/u/aa123)\
**Post date:** [16 November 2020 15:33 UTC](https://discourse.nodered.org/t/converting-datetime-to-dd-mm-yyyy-hh-mm/36012/1 "2020-11-16T15:33:52Z")

</div>

So I am currently converting DateTime to epoch time when parsing the date, it is doing in the format of mm/dd/yyyy hh:mm. How do I get it to dd/mm/yyyy:  
Here is the code so far:  
temp.JSON.parse(msg.payload);  
node.log(typeof temp)  
msg.payload=Date.parse(temp.payload.DateTime)/1000  
return msg.

I'm not sure what would be the best way to parse it

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2020 15:56 UTC](https://discourse.nodered.org/t/converting-datetime-to-dd-mm-yyyy-hh-mm/36012/2 "2020-11-16T15:56:14Z")

</div>

Have a look at the moment node. You can feed your time through that and convert it how you like. Alternatively if you want to do it in js then you can use the Date methods such as getMonth() [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)

---

<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:** [16 November 2020 16:12 UTC](https://discourse.nodered.org/t/converting-datetime-to-dd-mm-yyyy-hh-mm/36012/3 "2020-11-16T16:12:16Z")

</div>

No need to install extra nodes, as the change node has $moment() using JSONata expression. here is an example

```auto
[{"id":"a284d8c1.e2dd","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$now()","payloadType":"jsonata","x":590,"y":1760,"wires":[["3be8855b.56d692","8a900799.717ad8"]]},{"id":"3be8855b.56d692","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$moment(payload).tz(\"Europe/London\").format('DD-MM-YYYY HH:mm') \t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":1760,"wires":[["8a900799.717ad8"]]},{"id":"8a900799.717ad8","type":"debug","z":"8d22ae29.7df6d","name":"arrUpdateDate","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":1760,"wires":[]}]

```

---

<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:** [15 January 2021 16:12 UTC](https://discourse.nodered.org/t/converting-datetime-to-dd-mm-yyyy-hh-mm/36012/4 "2021-01-15T16:12:19Z")

</div>

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