# Specific timestamp from Node-Red to InfluxDB shell version 1.8.10

**URL:** <https://discourse.nodered.org/t/specific-timestamp-from-node-red-to-influxdb-shell-version-1-8-10/90501>\
**Category:** General\
**Tags:** database, function-node, influxdb, time\
**Created:** [28 August 2024 07:55 UTC](https://discourse.nodered.org/t/specific-timestamp-from-node-red-to-influxdb-shell-version-1-8-10/90501 "2024-08-28T07:55:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![King-of-Noobs](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@King-of-Noobs](https://discourse.nodered.org/u/King-of-Noobs)\
**Post date:** [28 August 2024 07:55 UTC](https://discourse.nodered.org/t/specific-timestamp-from-node-red-to-influxdb-shell-version-1-8-10/90501/1 "2024-08-28T07:55:31Z")

</div>

Hi community,

my first time in the forum since so far I was able to help myself (also thanks to the forum) but my current task is kind of challenging. The basic idea is kind of simple and I will explain on a minimum example: With Node-RED (using v4.0.2) I want to create a inject-pushed function, that gives a value (later different values) with a specific timestamp (defined by myself) to the influx Database (InfluxDB shell version 1.8.10) and get visualized by Grafana. The timestamp is always now+10s, so that the values are "already" in the dashboard.

```auto
[
    {
        "id": "2de6969d2c637700",
        "type": "debug",
        "z": "464b0d4053eb7bea",
        "name": "debug 185",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 1120,
        "wires": []
    },
    {
        "id": "3dc325a70c8f5e9a",
        "type": "influxdb out",
        "z": "464b0d4053eb7bea",
        "influxdb": "50fec97b649b4aa5",
        "name": "temperatur",
        "measurement": "temperatur",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 690,
        "y": 1160,
        "wires": []
    },
    {
        "id": "2c7a4cc6b5e1cfc6",
        "type": "inject",
        "z": "464b0d4053eb7bea",
        "name": "",
        "props": [],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 1120,
        "wires": [
            [
                "d517ee8d117e1942"
            ]
        ]
    },
    {
        "id": "d517ee8d117e1942",
        "type": "function",
        "z": "464b0d4053eb7bea",
        "name": "function 23",
        "func": "let futureTimestamp = Date.now() + 60000; // Beispiel-Zeitstempel in der Zukunft (in Millisekunden)\nlet timestampNs = futureTimestamp * 1000000; // Umrechnung in Nanosekunden\n\n// Den Payload im Line Protocol Format für InfluxDB setzen\nmsg.payload = -45;\nmsg.timestamp = timestampNs;\n\n// msg Objekt zurückgeben\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 1120,
        "wires": [
            [
                "2de6969d2c637700",
                "3dc325a70c8f5e9a"
            ]
        ]
    },
    {
        "id": "50fec97b649b4aa5",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "enasensors",
        "name": "enasensors",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://localhost:8086",
        "timeout": "10",
        "rejectUnauthorized": true
    }
]

```

Everything but the timestamp-transmission works. I really don't know how to format the payload, so that InfluxDB take my timestamp and not the systems one.

I am thankful for every hint and advice. So far I tested a lot but make no step forward.

Best regards and thanks in advance.

---

<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:** [28 August 2024 09:16 UTC](https://discourse.nodered.org/t/specific-timestamp-from-node-red-to-influxdb-shell-version-1-8-10/90501/2 "2024-08-28T09:16:10Z")

</div>

Welcome to the forum @King-of-Noobs

Try

```auto
// Den Payload im Line Protocol Format für InfluxDB setzen
msg.payload = {value: -45, time: timestampNs}

```

I am not certain, but I think that is right. It is a bit confusing, the timestamp field is actually called time.

In addition, if in the influx node, in the advanced options, you set the precision to millisecs then you won't need to convert to nanosecs.  
Finally, in modern javascript you generally don't need the semi colons, unless you put more than one statement on a line, which isn't a good idea anyway.

---

<div class="post-metadata">

**Author:** ![King-of-Noobs](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@King-of-Noobs](https://discourse.nodered.org/u/King-of-Noobs)\
**Post date:** [29 August 2024 06:36 UTC](https://discourse.nodered.org/t/specific-timestamp-from-node-red-to-influxdb-shell-version-1-8-10/90501/3 "2024-08-29T06:36:46Z")

</div>

Hi Colin,

first of all: thank you very much for your quick reply! I tried it and it works, thanks a lot. For all who are looking for a similar approach I post the working code below. Best regards!

```auto
[
    {
        "id": "b3d5eda1ee434aef",
        "type": "inject",
        "z": "53acd9b4e7811135",
        "name": "",
        "props": [],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1170,
        "y": 860,
        "wires": [
            [
                "a8b5d292c778eeb7"
            ]
        ]
    },
    {
        "id": "42ce1c002c4ebbea",
        "type": "debug",
        "z": "53acd9b4e7811135",
        "name": "debug 188",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1650,
        "y": 860,
        "wires": []
    },
    {
        "id": "a8b5d292c778eeb7",
        "type": "function",
        "z": "53acd9b4e7811135",
        "name": "function 22",
        "func": "function getFutureTimestamp(seconds) {\n const futureDate = new Date(Date.now() + (seconds * 1000));\n return futureDate.getTime(); \n}\n\nconst futureTimestamp = getFutureTimestamp(10);\n\nmsg.payload = {value:-45, time: futureTimestamp}\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1410,
        "y": 860,
        "wires": [
            [
                "42ce1c002c4ebbea",
                "f14062a41395a561"
            ]
        ]
    },
    {
        "id": "f14062a41395a561",
        "type": "influxdb out",
        "z": "53acd9b4e7811135",
        "influxdb": "50fec97b649b4aa5",
        "name": "temperatur",
        "measurement": "temperatur",
        "precision": "ms",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 1650,
        "y": 820,
        "wires": []
    },
    {
        "id": "50fec97b649b4aa5",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "enasensors",
        "name": "enasensors",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://localhost:8086",
        "timeout": "10",
        "rejectUnauthorized": true
    }
]

```

---

<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:** [29 August 2024 07:28 UTC](https://discourse.nodered.org/t/specific-timestamp-from-node-red-to-influxdb-shell-version-1-8-10/90501/4 "2024-08-29T07:28:41Z")

</div>

Just one small point.

```auto
function getFutureTimestamp(seconds) {
    var futureDate = new Date(Date.now() + (seconds * 1000));
    return futureDate.getTime();
}

var futureTimestamp = getFutureTimestamp(10);

msg.payload = {value:-45, time: futureTimestamp}

return msg;

```

Don't use `var`, use `let` or `const`. Both of those `var`s should be `const`.

---

<div class="post-metadata">

**Author:** ![King-of-Noobs](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@King-of-Noobs](https://discourse.nodered.org/u/King-of-Noobs)\
**Post date:** [29 August 2024 08:20 UTC](https://discourse.nodered.org/t/specific-timestamp-from-node-red-to-influxdb-shell-version-1-8-10/90501/5 "2024-08-29T08:20:50Z")

</div>

Thanks! I fixed it in the solution

---

<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:** [12 September 2024 08:21 UTC](https://discourse.nodered.org/t/specific-timestamp-from-node-red-to-influxdb-shell-version-1-8-10/90501/6 "2024-09-12T08:21:02Z")

</div>

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