# Nordpool data on graph

**URL:** <https://discourse.nodered.org/t/nordpool-data-on-graph/59256>\
**Category:** General\
**Created:** [2 March 2022 21:04 UTC](https://discourse.nodered.org/t/nordpool-data-on-graph/59256 "2022-03-02T21:04:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomasvjohansen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thomasvjohansen/32/32779_2.png) [@thomasvjohansen](https://discourse.nodered.org/u/thomasvjohansen)\
**Post date:** [2 March 2022 21:04 UTC](https://discourse.nodered.org/t/nordpool-data-on-graph/59256/1 "2022-03-02T21:04:04Z")

</div>

hi im trying to plot only future prices to my chart.

this plots one days hourly price from 0-23.

```auto
var msg1 = {}
for (var i = 0; i<msg.payload.length;i++){
    msg1 =
        {
        topic:msg.payload[i].Area + " " + msg.payload[i].Valuta, 
        payload:(msg.payload[i].Price/1000)+1.4725, 
        timestamp:msg.payload[i].StartTime,
        }
    node.send(msg1)
    }
return;

```

but I want it to only get values where StartTime is higher than current time.

adding something like if (now \< timestamp;)

```auto
var now = time();
var msg1 = {}
for (var i = 0; i<msg.payload.length;i++){
    msg1 = if (now < timestamp;)
        {
        topic:msg.payload[i].Area + " " + msg.payload[i].Valuta, 
        payload:(msg.payload[i].Price/1000)+1.4725, 
        timestamp:msg.payload[i].StartTime,
        }
    node.send(msg1)
    }
return;

```

but this obvious dont work. Whats the correct syntax, when It have to be in a array.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 March 2022 21:19 UTC](https://discourse.nodered.org/t/nordpool-data-on-graph/59256/2 "2022-03-02T21:19:42Z")

</div>

At a guess, without seeing real data...

```auto
const now = Date.now();
for (let i = 0; i < msg.payload.length; i++) {
    const el = msg.payload[i];
    if (el.StartTime > now) {
        node.send({
            topic: el.Area + " " + el.Valuta,
            payload: (el.Price / 1000) + 1.4725,
            timestamp: el.StartTime,
        });
    }
}
return;

```

↑ assumes `StartTime` is a Js epoch

if not, change it to ...

```auto
const now = Date.now();
for (let i = 0; i < msg.payload.length; i++) {
    const el = msg.payload[i];
    if (Date.parse(el.StartTime) > now) {
        node.send({
            topic: el.Area + " " + el.Valuta,
            payload: (el.Price / 1000) + 1.4725,
            timestamp: el.StartTime,
        });
    }
}
return;

```

---

<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 21:24 UTC](https://discourse.nodered.org/t/nordpool-data-on-graph/59256/3 "2022-03-02T21:24:03Z")

</div>

What format is StartTime?

If it is in milliseconds or is a javascript date then you should be able to do

```auto
    if (msg.payload[i].StartTime > now) {
        msg1 = 
        {
            topic:msg.payload[i].Area + " " + msg.payload[i].Valuta, 
            payload:(msg.payload[i].Price/1000)+1.4725, 
            timestamp:msg.payload[i].StartTime,
        }
        node.send(msg1)
    }

```

You said you only wanted data when StartTime higher than current. If you actually meant the same or higher then use `>= now`

---

<div class="post-metadata">

**Author:** ![thomasvjohansen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thomasvjohansen/32/32779_2.png) [@thomasvjohansen](https://discourse.nodered.org/u/thomasvjohansen)\
**Post date:** [2 March 2022 21:32 UTC](https://discourse.nodered.org/t/nordpool-data-on-graph/59256/4 "2022-03-02T21:32:33Z")

</div>

the data is this:

```auto
object
Area: "DK2"
Timestamp: "2022-03-02 00:00"
StartTime: "2022-03-02 00:00"
EndTime: "2022-03-02 01:00"
Price: 1867.04
Valuta: "DKK/MWh"

```

---

<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 21:48 UTC](https://discourse.nodered.org/t/nordpool-data-on-graph/59256/5 "2022-03-02T21:48:03Z")

</div>

In that case you will have to parse the date into a js object as suggested by Steve.

**[Edit]** If the timestamps are not UTC then you will have to adjust for that.

---

<div class="post-metadata">

**Author:** ![thomasvjohansen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thomasvjohansen/32/32779_2.png) [@thomasvjohansen](https://discourse.nodered.org/u/thomasvjohansen)\
**Post date:** [2 March 2022 22:28 UTC](https://discourse.nodered.org/t/nordpool-data-on-graph/59256/6 "2022-03-02T22:28:24Z")

</div>

thx @Steve-Mcl & @Colin I think it works. will test it over the next day.

---

<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 22:28 UTC](https://discourse.nodered.org/t/nordpool-data-on-graph/59256/7 "2022-05-01T22:28:39Z")

</div>

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