# Change node not replacing text

**URL:** https://discourse.nodered.org/t/change-node-not-replacing-text/41013
**Category:** General
**Created:** [15 February 2021 10:23 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013 "2021-02-15T10:23:48Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [15 February 2021 10:23 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/1 "2021-02-15T10:23:48Z")

</div>

I'm sure I am missing something obvious, but why isn't this working? Tried with and without quotes.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/5/a546ccb636681e35f3356a3b0a84b90bcc9fd0b0.png)

Output (and input)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da5768fe7f5eacbb299d9d36e53d0d61b0901cc7.png)

I'm wondering if it is trying whole text match? I'm sure I have done this before.

---

<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: [15 February 2021 10:39 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/2 "2021-02-15T10:39:01Z")

</div>

It probably isn't a string, but a javascript date, which the debug node is helpfully displaying in a readable form. In a function node put  
`node.warn(typeof msg.time)`  
and see what it says.

Why do you need this? I can't imagine a use case.

---

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [15 February 2021 11:39 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/3 "2021-02-15T11:39:24Z")

</div>

> [@Colin](#):
>
> Why do you need this? I can't imagine a use case.

Python does not convert times in the form 'Z' despite it being ISO standard as the `fromISO` method is the inverse of the `toISO` method and the `toISO` method does not generate a Z format just a +00:00 format.

> [@Colin](#):
>
> In a function node put `node.warn(typeof msg.time)` and see what it says.

Type Object so looks like you are correct (I think).

---

<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: [15 February 2021 11:54 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/4 "2021-02-15T11:54:40Z")

</div>

That doesn't explain what your use case is. What are you doing with the timestamp after you have modified it?

---

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [15 February 2021 11:57 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/5 "2021-02-15T11:57:41Z")

</div>

Sending it to another process that (might) use Python to manipulate the time. If it finds Z, Pyton assumes it is a local time/Date string. Not what I want.

How do I tell Javascript this is a time Object. It seems to helpfully know it isn't a string, but refuses to allow date/time methods on it ☹

Do I need to declare a new date object?

[edit]  
Doh! a while since I have done Javascript - it is case sensitive.

---

<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: [15 February 2021 12:05 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/6 "2021-02-15T12:05:11Z")

</div>

I think the question you need to ask is how to I convert a javascript Date into a string of the form you want.  
You could use toISOString() and then change the Z as you have already tried, or I expect you could use node-red-contrib-moment. Probably several other ways.

I am astonished that Python will not handle an ISO date.

---

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [15 February 2021 12:06 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/7 "2021-02-15T12:06:16Z")

</div>

> [@Colin](#):
>
> I am astonished that Python will not handle an ISO date.

It does handle ISO dates just not ones with Z as a suffix.

[edit]  
Unless something has changed recently.

[edit2]  
Thanks

```auto
msg.time = msg.time.toISOString().replace("Z", "+00:00");

```

---

<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: [15 February 2021 12:10 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/8 "2021-02-15T12:10:04Z")

</div>

Google suggests that `python-dateutil` will do it.

---

<div class="post-metadata">

### Author: ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)
#### Post date: [15 February 2021 13:19 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/9 "2021-02-15T13:19:33Z")

</div>

Yes I know about that package, but it is not a core package.

I'd rater always export data out of NR that is in a time format that cannot be misinterpreted. I mostly convert to an integer.

---

<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: [16 April 2021 13:20 UTC](https://discourse.nodered.org/t/change-node-not-replacing-text/41013/10 "2021-04-16T13:20:07Z")

</div>

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