# Timestamp into the chart

**URL:** https://discourse.nodered.org/t/timestamp-into-the-chart/29863
**Category:** General
**Created:** [10 July 2020 16:33 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863 "2020-07-10T16:33:05Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [10 July 2020 16:33 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/1 "2020-07-10T16:33:05Z")

</div>

Hello,

I am trying to figure out how to chart my DynamoDB values into the chart. Currently I am getting the data with timestamp from DynamoDB which I can view it in Node-red. Problem I get is getting the data into the chart. I tried doing some test with manually entering the data and found the issue.

Right now the timestamp I get from DynamoDb reads like Time: "2020-07-02T13:25:06.468-7:00". I can not plot this into the chart but if I change the timestamp into Time: "2020-07-02T13:25:06.468" then it works good.

Is there any way to remove the "-7:00" evertime I get data from DynamoDB.

Thank you

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [10 July 2020 18:13 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/2 "2020-07-10T18:13:05Z")

</div>

Well you could use the string split() function of Javascript in a `function` node, or you could use the $split() function in JSONata in a `change` or if it is always a -7:00 you could use the replace option in the `change` node. Or you could probably use node-red-contrib-string.

---

<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: [10 July 2020 19:45 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/3 "2020-07-10T19:45:12Z")

</div>

When it shows 13:25:06 -7 what is the actual local time and what time zone are you in (GMT-7?)

---

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [10 July 2020 20:08 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/4 "2020-07-10T20:08:27Z")

</div>

Local time is same as 13:25:06. I am in Pacific time zone

---

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [10 July 2020 20:10 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/5 "2020-07-10T20:10:20Z")

</div>

Its always same -7:00. I tired using the chnage option in change node but it did not get rid of it. I will try other options. Thanks

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [10 July 2020 20:35 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/6 "2020-07-10T20:35:44Z")

</div>

It is really simple, try this.

```auto
[{"id":"fa446d8f.76d148","type":"inject","z":"ccdf63.79a950a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2020-07-02T13:25:06.468-7:00","payloadType":"str","x":200,"y":120,"wires":[["14c9a896.bacf07","1c2fa9b3.5419b6"]]},{"id":"a341340a.618478","type":"debug","z":"ccdf63.79a950a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":120,"wires":[]},{"id":"14c9a896.bacf07","type":"change","z":"ccdf63.79a950a","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"-7:00","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":120,"wires":[["a341340a.618478"]]},{"id":"1c2fa9b3.5419b6","type":"debug","z":"ccdf63.79a950a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":360,"y":180,"wires":[]}]

```

---

<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: [10 July 2020 20:45 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/7 "2020-07-10T20:45:32Z")

</div>

If you feed that into a chart node (without the -7) doesn't it assume it is GMT, and therefore show the wrong time on the chart?

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [10 July 2020 20:51 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/8 "2020-07-10T20:51:15Z")

</div>

> [@Ref\_A](#):
>
> Is there any way to remove the "-7:00" evertime I get data from DynamoDB.

A better option would be to fix that datetime string by changing your DynamoDB query to output a timestamp or UTC string. Since I don't know that database, I cannot tell you how to change the query, but most DBs have various formatting options for outputting dates...

So a slightly less desirable solution is to post-process the string, but KEEP the timezone offset, so you don't lose information. As you noted, the existing string with the `-7:00` is NOT recognized by the Javascript Date parser -- however, `-07:00` IS valid:

```auto
> new Date("2020-07-02T13:25:06.468-7:00")
Invalid Date
> new Date("2020-07-02T13:25:06.468-07:00")
2020-07-02T20:25:06.468Z

```

So you could use a regex to replace that missing leading 0, something like this:

```auto
> "2020-07-02T13:25:06.468-7:00".replace(/([+-])(\d):/, "$10$2:")
'2020-07-02T13:25:06.468-07:00'

```

and then format the JS Date object to your local timezone...

> [@Ref\_A](#):
>
> Its always same -7:00

If your locale observes Daylight Savings, then part of the year it will show `-8:00`, most likely. So removing that information is not recommended. I like Colin's idea of feeding the chart node with the datetime string (no conversion to Date necessary) -- just make sure to add the leading `0` to the timezone offset first.

---

<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: [10 July 2020 20:59 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/9 "2020-07-10T20:59:34Z")

</div>

I am somewhat surprised that Dynamodb provides non-ISO format timestamps. Does the database know it is a timestamp or is it being written into the database as that string?

---

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [10 July 2020 21:11 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/10 "2020-07-10T21:11:46Z")

</div>

What's happening is that PLC is collecting the data with the timestamp and sending it to AWS iOT Core where it gets transferred into the DynamoDB. So the timestamp is already in the data and DynamoDB is just storing it as it is . From dynamoDB I wanted it to send to node red to plot the chart.

Chart shows the correct time even if I take the -7:00 out of the timestamp

---

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [10 July 2020 21:17 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/11 "2020-07-10T21:17:55Z")

</div>

Thank you. Yeah I did not think about the daylight saving time changing the time. I did as you mentioned by adding the .replace at the end. The result I get is "2020-07-02T13:25:06.468-07:00".

But when I add new Date in the front, it gives me the error message saying "TypeError: (intermediate value).replace is not a function"

Any Suggestions why would it give me this error

---

<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: [11 July 2020 07:26 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/12 "2020-07-11T07:26:11Z")

</div>

> [@Ref\_A](#):
>
> "TypeError: (intermediate value).replace is not a function"

I presume that is in a function node. If it is then post the code of the function node (use the `</>` button in the forum) and show us the debug output of the message going in.

---

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [13 July 2020 17:11 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/13 "2020-07-13T17:11:19Z")

</div>

```auto
var i = 0;
var x = 0;
var myArray1 = [];

for (i = 0; i < msg.payload.ScannedCount; i++) {
    if (msg.payload.Items[i].ID.N == 0){
        myArray1[x] = {
           "Time":(msg.payload.Items[i].topic.M.Time.S).replace(/([+-])(\d):/, "$10$2:"),
           "Poly_Level": Number(msg.payload.Items[i].topic.M.Values.M.Poly_Level.N),
           
           
        }
     
       x = x+1;
    }
}

var chart = [{
    "series":["Level ="],
    "data":[myArray1],
    "labels":[""]
}];

msg.payload = chart;

return msg;

```

This is the function node that I use convert the time. If I dont put new Date in front of time than it gives me that error.

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

this is what goes into the function node

---

<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 July 2020 20:00 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/14 "2020-07-13T20:00:29Z")

</div>

Earlier you said

> [@Ref\_A](#):
>
> But when I add new Date in the front, it gives me the error message

Now you say

> [@Ref\_A](#):
>
> If I dont put new Date in front of time than it gives me that error.

So I am confused. Does the function you posted give the error? If not then what does give the error?

---

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [13 July 2020 20:03 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/15 "2020-07-13T20:03:27Z")

</div>

Sorry mistyped it. If I add new Date it gives me the error. Above function does not give the error.

```auto
var i = 0;
var x = 0;
var myArray1 = [];

for (i = 0; i < msg.payload.ScannedCount; i++) {
    if (msg.payload.Items[i].ID.N == 0){
        myArray1[x] = {
           "Time":new Date(msg.payload.Items[i].topic.M.Time.S).replace(/([+-])(\d):/, "$10$2:"),
           "Poly_Level": Number(msg.payload.Items[i].topic.M.Values.M.Poly_Level.N),
           
           
        }
     
       x = x+1;
    }
}

var chart = [{
    "series":["Level ="],
    "data":[myArray1],
    "labels":[""]
}];

msg.payload = chart;

return msg;

```

This does give the error. Only difference is new Date infront of time

---

<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 July 2020 20:15 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/16 "2020-07-13T20:15:54Z")

</div>

It should be

```auto
"Time":new Date(msg.payload.Items[i].topic.M.Time.S.replace(/([+-])(\d):/, "$10$2:")),

```

However, as you found the chart is ok with the string so you might as well just let it do the conversion for you. It is always good to know why something doesn't work though, so it is less likely to happen again.

---

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [13 July 2020 21:49 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/18 "2020-07-13T21:49:14Z")

</div>

Thank you Colin. It solved the issue with Time, now I can see -- Time: "2020-07-02T16:26:38.449Z"  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4fe04982358f23ec31bdf8f29af8e6ee3c4c350b.png)

But it still shows the chart like this

---

<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: [14 July 2020 07:47 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/19 "2020-07-14T07:47:00Z")

</div>

If you look at the [docs for the chart node](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md) it shows the data should be formatted like this

```auto
[{
"series": ["A", "B", "C"],
"data": [
    [{ "x": 1504029632890, "y": 5 },
     { "x": 1504029636001, "y": 4 },
     { "x": 1504029638656, "y": 2 }
    ],
    [{ "x": 1504029633514, "y": 6 },
     { "x": 1504029636622, "y": 7 },
     { "x": 1504029639539, "y": 6 }
    ],
    [{ "x": 1504029634400, "y": 7 },
     { "x": 1504029637959, "y": 7 },
     { "x": 1504029640317, "y": 7 }
    ]
],
"labels": [""]
}]

```

In your data array you have the properties Time and Poly\_Level instead of x and y.  
If that doesn't work fix it then feed the output of the function into a debug node, and show us what it shows.

---

<div class="post-metadata">

### Author: ![Ref\_A](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ref\_A](https://discourse.nodered.org/u/Ref_A)
#### Post date: [14 July 2020 17:20 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/20 "2020-07-14T17:20:42Z")

</div>

Thank you Colin

---

<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: [28 July 2020 17:20 UTC](https://discourse.nodered.org/t/timestamp-into-the-chart/29863/21 "2020-07-28T17:20:49Z")

</div>

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