# InfluxDB keed time formating

**URL:** <https://discourse.nodered.org/t/influxdb-keed-time-formating/50009>\
**Category:** General\
**Created:** [22 August 2021 11:41 UTC](https://discourse.nodered.org/t/influxdb-keed-time-formating/50009 "2021-08-22T11:41:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duser](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Duser](https://discourse.nodered.org/u/Duser)\
**Post date:** [22 August 2021 11:41 UTC](https://discourse.nodered.org/t/influxdb-keed-time-formating/50009/1 "2021-08-22T11:41:45Z")

</div>

Hello.  
I use [node-red-contrib-influxdb](https://flows.nodered.org/node/node-red-contrib-influxdb).  
After query it returns time as "2021-08-21T16:50:28.552Z" (if I set RAW it has microseconds).

```auto
{"_msgid":"2535bbc93736d80a","payload":[
{"time":"2021-08-21T16:50:28.552Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"},
{"time":"2021-08-21T16:51:28.522Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"},
{"time":"2021-08-21T16:53:28.544Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"},
{"time":"2021-08-21T18:45:23.572Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"},
{"time":"2021-08-22T08:10:35.013Z","BME280_Pressure":909.68,"BME280_Temperature":-146.93,"hostname":"weather"}],"topic":""}

```

If i do the same in console:

```auto
time BME280_Pressure BME280_Temperature hostname
---- --------------- ------------------ --------
1629564628552540290 909.68 -146.93 weather
1629564688522635965 909.68 -146.93 weather
1629564808544065157 909.68 -146.93 weather
1629571523572056292 909.68 -146.93 weather
1629619835013378116 909.68 -146.93 weather

```

After it I use 2 func:

func1()  
`return [msg.payload];`

func2()

```auto
msg.query="delete from database WHERE time='"+msg.time"'";
return msg;

```

I have trouble with deleting it from influx. I need use time in microseconds (1629564628552540290), but node-red-contrib-influxdb converts it with js.

1. How can I disable converting time and keep it as influx API returns?  
or
2. How can I convert it back to microseconds? (valueof() returns miliseconds only).  
or
3. I fond convertTimeToNanos() function in [influxdb-client-js](https://influxdata.github.io/influxdb-client-js/influxdb-client.converttimetonanos.html) but i can't find out how can I use this function?

My flow:

```auto
[
    {
        "id": "416a6bb38ccb8a89",
        "type": "influxdb in",
        "z": "50e7cc8e7bad66aa",
        "influxdb": "5c85923c32f22a0f",
        "name": "SensorErrors",
        "query": "select BME280_Pressure,BME280_Temperature,hostname from mqttc where time > now() - 1d and BME280_Temperature < -100 OR BME280_Pressure > 800 OR BME280_Pressure < 660",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 250,
        "y": 300,
        "wires": [
            [
                "36db782fed6f8bc5",
                "1593075f4457d115"
            ]
        ],
        "icon": "font-awesome/fa-info-circle"
    },
    {
        "id": "287f160d085e6db1",
        "type": "inject",
        "z": "50e7cc8e7bad66aa",
        "name": "Run",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 90,
        "y": 300,
        "wires": [
            [
                "416a6bb38ccb8a89"
            ]
        ]
    },
    {
        "id": "2e52885e4a0345ab",
        "type": "influxdb in",
        "z": "50e7cc8e7bad66aa",
        "influxdb": "5c85923c32f22a0f",
        "name": "DeleteWrong",
        "query": "",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 870,
        "y": 300,
        "wires": [
            []
        ],
        "icon": "font-awesome/fa-remove"
    },
    {
        "id": "41cab9442b0a932c",
        "type": "function",
        "z": "50e7cc8e7bad66aa",
        "name": "",
        "func": "msg.query=\"delete from mqttc WHERE time='\"+msg.time\"'\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 580,
        "y": 300,
        "wires": [
            [
                "36db782fed6f8bc5",
                "2e52885e4a0345ab"
            ]
        ]
    },
    {
        "id": "36db782fed6f8bc5",
        "type": "debug",
        "z": "50e7cc8e7bad66aa",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 380,
        "wires": []
    },
    {
        "id": "1593075f4457d115",
        "type": "function",
        "z": "50e7cc8e7bad66aa",
        "name": "",
        "func": "return [msg.payload];",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 300,
        "wires": [
            [
                "41cab9442b0a932c"
            ]
        ]
    },
    {
        "id": "5c85923c32f22a0f",
        "type": "influxdb",
        "hostname": "172.16.95.15",
        "port": "8086",
        "protocol": "http",
        "database": "arduino",
        "name": "influxdb",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://172.16.95.15:8086",
        "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:** [25 August 2021 09:12 UTC](https://discourse.nodered.org/t/influxdb-keed-time-formating/50009/2 "2021-08-25T09:12:35Z")

</div>

> [@Duser](#):
>
> func1()  
> `return [msg.payload];`

It is probably more efficient to use a split node for that.

What have you specified for the timestamp resolution in the advanced settings of the influx node?

Are you sure it is returning a string for the timestamp? What do you see if you add this to the start of the second function  
`node.warn(typeof msg.time)`

---

<div class="post-metadata">

**Author:** ![Duser](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Duser](https://discourse.nodered.org/u/Duser)\
**Post date:** [25 August 2021 11:13 UTC](https://discourse.nodered.org/t/influxdb-keed-time-formating/50009/3 "2021-08-25T11:13:12Z")

</div>

I was able to do it but other way.

I meet a couple of troubles:

1. [node-red-contrib-influxdb](https://flows.nodered.org/node/node-red-contrib-influxdb) generate wrong request. If I select nanosec then module set "epoch=" instead of "epoch=ns". innflux returns text date (not integer value). I replace it regular "http request".

2. JS can't work with long int. And I have to use bigInt to parse my json and process it.

---

<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:** [8 September 2021 11:13 UTC](https://discourse.nodered.org/t/influxdb-keed-time-formating/50009/4 "2021-09-08T11:13:58Z")

</div>

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