# Strange Data from postgres node

**URL:** https://discourse.nodered.org/t/strange-data-from-postgres-node/59188
**Category:** General
**Created:** [1 March 2022 17:26 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188 "2022-03-01T17:26:42Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![markush](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@markush](https://discourse.nodered.org/u/markush)
#### Post date: [1 March 2022 17:26 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/1 "2022-03-01T17:26:42Z")

</div>

Hello,

i'm trying to implement a bar display of some data stored in a postgres database. With a query executed in Postbird Tool i get the following output:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fbf66690b1543efc1bab28007dfe442ef4501a91.png)

The query in node-red with a function node and a postgres node looks like this:

msg.payload = 'select distinct(event\_date) as label, max(energytoday) as payload from smarthome.pv group by event\_date';  
return msg;

The returned data looks like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27c32356ef81b1e6b723957ac9dd44226686db9e.png)

The date fields in the label column wrong!? There exists no date "2022-02-24" in the database! But why is it so? event\_date is a "normal" date field in the database.

Greets

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [1 March 2022 17:31 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/2 "2022-03-01T17:31:32Z")

</div>

The dates returned by your sql query are Zulu time.  
What time zone are you in?  
How did you insert the data?

---

<div class="post-metadata">

### Author: ![markush](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@markush](https://discourse.nodered.org/u/markush)
#### Post date: [1 March 2022 17:37 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/3 "2022-03-01T17:37:02Z")

</div>

My time zone is Europe\Berlin. Insert query uses the 'current\_date' function for storying the date field.

Postbird shows the stored data with correct date field:

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

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [1 March 2022 17:46 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/4 "2022-03-01T17:46:26Z")

</div>

Maybe postbird is displaying the times in your local time? That would show the first record from your query as 22-02-25 00:00

---

<div class="post-metadata">

### Author: ![markush](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@markush](https://discourse.nodered.org/u/markush)
#### Post date: [1 March 2022 17:53 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/5 "2022-03-01T17:53:50Z")

</div>

Yes, that would be possible...  
In the end: i have to convert that values to my local timezone!?!?

---

<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: [1 March 2022 18:30 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/6 "2022-03-01T18:30:34Z")

</div>

That depends on what you want to do with it. The date/time it is giving you is midnight local time, which I presume it's what you want. What you going to do with it?

---

<div class="post-metadata">

### Author: ![markush](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@markush](https://discourse.nodered.org/u/markush)
#### Post date: [1 March 2022 18:35 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/7 "2022-03-01T18:35:51Z")

</div>

I want to show a bar graph at the dasboard. Therefore i need the local time. Found a possible solution to convert it:

> console.log(event.toLocaleString('en-GB', { timeZone: 'UTC' }));

But every record must be converted...

---

<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: [1 March 2022 18:49 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/8 "2022-03-01T18:49:29Z")

</div>

If you are using the dashboard chart node it will expect the timestamps in UTC which is what you have. The chart node will display it in local time.

---

<div class="post-metadata">

### Author: ![markush](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@markush](https://discourse.nodered.org/u/markush)
#### Post date: [1 March 2022 19:06 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/9 "2022-03-01T19:06:08Z")

</div>

Thank you for this information! I will try it with the chart node.

---

<div class="post-metadata">

### Author: ![markush](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@markush](https://discourse.nodered.org/u/markush)
#### Post date: [2 March 2022 09:58 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/10 "2022-03-02T09:58:03Z")

</div>

Sure it shows using the local time settings? I tried and get the following display:

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

The object for this data:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39492a4b367fc1c532f6aedfcf1f6e8e8e40df3e.png)

Is there a special way for the chart node to show the correct Date?

---

<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: [2 March 2022 10:49 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/11 "2022-03-02T10:49:43Z")

</div>

Sorry, I missed that you were using a bar chart. My comment was about the line chart.

For bar chart labels you will have to format the label yourself.

---

<div class="post-metadata">

### Author: ![markush](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@markush](https://discourse.nodered.org/u/markush)
#### Post date: [2 March 2022 12:20 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/12 "2022-03-02T12:20:26Z")

</div>

Okay, thats interesting!

Thank your for you help! 👍

---

<div class="post-metadata">

### Author: ![markush](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@markush](https://discourse.nodered.org/u/markush)
#### Post date: [2 March 2022 13:52 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/13 "2022-03-02T13:52:29Z")

</div>

Here is my solution to show data from a postgresql database in a bar chart:

Object from the database:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/8/e81914349680b4c2670b37f7129f6ec2100edeee.png)

Object for the ui\_chart:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c32f06777676392c64edbce4ba4ceb3ab8fd73a3.png)

Here is the code for the function node to convert the data from one object to the other:

```auto
var load = msg.payload;
var labels = [];
var data = [];

for(let i = load.length - 1; i >= 0; i--) {
    //node.warn(load[i].event_date);
    labels.push((load[i].event_date.toLocaleDateString('de-DE')));
    data.push(load[i].energytoday);
}
//node.warn(labels +' ' + data);

msg.payload=[{
    "series": [],
    "data": [data],
    "labels": labels
}];

return msg;

```

Maybe it will be helpful for someone!

---

<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: [1 May 2022 13:53 UTC](https://discourse.nodered.org/t/strange-data-from-postgres-node/59188/14 "2022-05-01T13:53:27Z")

</div>

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