# Change DateTime format

**URL:** <https://discourse.nodered.org/t/change-datetime-format/5754>\
**Category:** General\
**Created:** [13 December 2018 10:53 UTC](https://discourse.nodered.org/t/change-datetime-format/5754 "2018-12-13T10:53:53Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cabriopuma](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@cabriopuma](https://discourse.nodered.org/u/cabriopuma)\
**Post date:** [13 December 2018 10:53 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/1 "2018-12-13T10:53:53Z")

</div>

Hi @ all,  
at the moment I'm coming not to the solution about that.  
How could I change the format 2018-12-13T07:03:00.000+0000  
only to the time? (In that case to 07:03 or 7.30). Would be  
great for any kind of help.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [13 December 2018 11:21 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/2 "2018-12-13T11:21:55Z")

</div>

You can do this in several ways  
One of them is to use a JSONata expression in a change node that will pick out a part of a payload

something like this ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0fc6d050ab6bb68eb30c87982322f51547b7e691.png)

replace start with a number that picks out the 0 from 07: and change length to be how many characters you want (5)

---

<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:** [13 December 2018 13:56 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/3 "2018-12-13T13:56:58Z")

</div>

> [@cabriopuma](#):
>
> 2018-12-13T07:03:00.000+0000

Where is that coming from and what type is it? Is it a string or a Unix timestamp or what?

---

<div class="post-metadata">

**Author:** ![cabriopuma](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@cabriopuma](https://discourse.nodered.org/u/cabriopuma)\
**Post date:** [13 December 2018 17:09 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/4 "2018-12-13T17:09:14Z")

</div>

> [@cymplecy](#):
>
> t

Hi Colin,  
it is coming from openhab and it is a DateTime type.  
(openhab.0.items.astro\_sun\_home\_rise\_start)

---

<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:** [13 December 2018 17:12 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/5 "2018-12-13T17:12:50Z")

</div>

Not sure what you mean by coming from openhab as I don't use openhab. Perhaps the best thing is to feed it into a debug node and show us a screenshot of the result.

---

<div class="post-metadata">

**Author:** ![cabriopuma](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@cabriopuma](https://discourse.nodered.org/u/cabriopuma)\
**Post date:** [13 December 2018 17:15 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/6 "2018-12-13T17:15:38Z")

</div>

![node%20red](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c63865144085a2170f6ed747a9eafda9b45b7be0.png)

Hi attached my screenshot.

---

<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:** [13 December 2018 17:16 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/7 "2018-12-13T17:16:50Z")

</div>

I meant a screenshot of what you see in the debug node.  
[Edit] so what is in the debug pane

---

<div class="post-metadata">

**Author:** ![cabriopuma](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@cabriopuma](https://discourse.nodered.org/u/cabriopuma)\
**Post date:** [13 December 2018 17:22 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/8 "2018-12-13T17:22:11Z")

</div>

I'm sorry...

 ![node%20red](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/09a65655a22abc691dcf5a7364cafcaa7e39feb8.png)

---

<div class="post-metadata">

**Author:** ![cabriopuma](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@cabriopuma](https://discourse.nodered.org/u/cabriopuma)\
**Post date:** [13 December 2018 17:26 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/9 "2018-12-13T17:26:39Z")

</div>

Hi cymplecy ,  
i try that but didn't work.

---

<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:** [13 December 2018 17:31 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/10 "2018-12-13T17:31:04Z")

</div>

Well the first thing you can see from the debug is that the time is not in `msg.payload`, but in `msg.payload.val`, so you would need to provide `payload.val` in the change string.  
Personally I would not do it like that, I would feed it into a moment node, I think that should be capable of doing what you want.  
[Edit] That is node-red-contrib-moment

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [13 December 2018 17:42 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/11 "2018-12-13T17:42:28Z")

</div>

Since your time is in payload.val, try

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

---

<div class="post-metadata">

**Author:** ![cabriopuma](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@cabriopuma](https://discourse.nodered.org/u/cabriopuma)\
**Post date:** [13 December 2018 20:03 UTC](https://discourse.nodered.org/t/change-datetime-format/5754/12 "2018-12-13T20:03:31Z")

</div>

Thank you guys! 🙂 Wonderful job!

Colin your Idea was great, because by the  
other example I had the prob that the seconds  
were still there at the end. So thank you very much!!!

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