# SUBSTR in Change Node - HELP Needed

**URL:** <https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148>\
**Category:** General\
**Created:** [23 November 2022 23:03 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148 "2022-11-23T23:03:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [23 November 2022 23:03 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148/1 "2022-11-23T23:03:12Z")

</div>

Hi all

I have a Date and Time string - a runrise date and time - which I am simply looking to extract the time. from. But I keep getting an "undefined" result in the debug messages

Here is a string sample - "2022-11-23T08:04:01+0000"

I have a change node to give me msg.payload from msg.payload.sunriseTimeLocal.substr(11,5), so it doesn't like the substr(11,5)

Where am I going wrong please ?

---

<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:** [24 November 2022 00:37 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148/2 "2022-11-24T00:37:54Z")

</div>

Change nodes are static unless you use JSONata, you can't use JavaScript.

---

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [25 November 2022 21:13 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148/3 "2022-11-25T21:13:59Z")

</div>

Ah ha,

As it turns out, it IS part of JSON Data. The actual element (if that is the correct word !!) is  
payload.sunriseTimeLocal[0]

It contains "2022-11-23T08:04:01+0000"

So how would I get 08:04 out of this

 ![capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a0083f26f993258f786aab6d5444f3ff5bddda5.jpeg)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [26 November 2022 07:56 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148/4 "2022-11-26T07:56:34Z")

</div>

You can use the change node with a JSONata expression:

```auto
payload.sunriseTimeLocal.$moment($).utc().format("HH:mm")

```

 ![SCR-20221126-cd0](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/842fde8b67b613ca031bfc1e54a9053838613c16.png)

If you only want the first one in the array

```auto
$moment(payload.sunriseTimeLocal[0]).utc().format("HH:mm")

```

---

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [26 November 2022 10:36 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148/5 "2022-11-26T10:36:13Z")

</div>

Thanks for that. I must be missing a plugin or some node. I have the Moment plugin installed. I only need the first one in the array

 ![capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4bf2619af62a4048ab11edbd5a1d9ddc320acec5.jpeg)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [26 November 2022 10:38 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148/6 "2022-11-26T10:38:02Z")

</div>

You don't need the moment plugin, it is part of the jsonata package within node-red.

How did you configure the change node ? Did you set it to an jsonata expression ?

---

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [26 November 2022 11:38 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148/7 "2022-11-26T11:38:23Z")

</div>

Ah - I missed the jsonata expression bit

---

<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:** [10 December 2022 11:39 UTC](https://discourse.nodered.org/t/substr-in-change-node-help-needed/71148/8 "2022-12-10T11:39:08Z")

</div>

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