# Specified time in Influx object

**URL:** <https://discourse.nodered.org/t/specified-time-in-influx-object/46703>\
**Category:** Dashboard\
**Created:** [4 June 2021 13:07 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703 "2021-06-04T13:07:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![derko](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@derko](https://discourse.nodered.org/u/derko)\
**Post date:** [4 June 2021 13:07 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/1 "2021-06-04T13:07:33Z")

</div>

I'm receiving in HTTP IN a JSON containing, among other things, an id, some timestamps and some fields.  
I need to store the fields into an InfluxDB by tag id and by timestamp.  
So I create an JSON-object array. But I am unsure where to place the timestamp. InfluxDB only stores the object under the current timestamp of receiving.  
This is the code in the function that creates the Object for the influxdb-node.

```auto

object=[];
nr=msg.payload.reports.length;
for (var i = 0; i < nr; i++) {
   
 var obj = [
  
  msg.payload.reports[i], // contains the fields
  {
   id: msg.payload.imei.toString() // contains the tag
  },
// {
// time: msg.payload.reports[i].timestamp*1000000000
// }
 
 ]
 object.push(obj);
 
}

msg.payload=object;
return msg;

```

Wherever I set the timestamp, it never comes as such in InfluxDB.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [4 June 2021 13:25 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/2 "2021-06-04T13:25:02Z")

</div>

I'm using myself the code blow. Works great.  
Don't think it's needed to correct for nano seconds if you have the time precision set to **default** in the influx out node.

```auto
var newmsg =[{
    Temperature:temp,
    Pressure:hkpa,
    time:new Date()
}]

```

---

<div class="post-metadata">

**Author:** ![derko](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@derko](https://discourse.nodered.org/u/derko)\
**Post date:** [4 June 2021 14:44 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/3 "2021-06-04T14:44:01Z")

</div>

Thanks!  
Now I've got it working. I thought time is a special thing in Influx. Like tags and fields. But time is just a field. So when added to the fields-object it will work

```auto
 fields=msg.payload.reports[i];
 fields.time=msg.payload.reports[i].timestamp*1000000000; 
 var obj = [
  
  fields,
  {
   id: msg.payload.imei.toString()
  }
 ]

```

---

<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:** [5 June 2021 08:16 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/4 "2021-06-05T08:16:32Z")

</div>

> [@derko](#):
>
> But time is just a field.

Not quite. It _is_ a field, but it isn't _just_ a field, it a field with additional features and handling.  
What does the above code give you in your `obj` array? Is that what you are passing on the influx?

---

<div class="post-metadata">

**Author:** ![derko](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@derko](https://discourse.nodered.org/u/derko)\
**Post date:** [5 June 2021 12:44 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/5 "2021-06-05T12:44:36Z")

</div>

This gives me two objects. The first containing the fields and the time, the second containing the tag.  
This is passed to the Influx-node.

From the Info of the Influx-node:

> If **msg.payload** is an array containing two objects, the first object will be written as the set of named fields, the second is the set of named tags.

And in the Info there is no mention of what to do with the time. But as i now found out time has to be part of the first object. I.e. the object containing the fields.

---

<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:** [5 June 2021 13:06 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/6 "2021-06-05T13:06:57Z")

</div>

> [@derko](#):
>
> This gives me two objects. The first containing the fields and the time, the second containing the tag.

Yes, of course.  
The full readme on github does include additional information about more unusual use cases, I believe.

---

<div class="post-metadata">

**Author:** ![derko](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@derko](https://discourse.nodered.org/u/derko)\
**Post date:** [5 June 2021 13:16 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/7 "2021-06-05T13:16:54Z")

</div>

But it is not that unusual wanting a specific time inserted into InfluxDB instead of the current time of inserting?  
But thanks to this forum I am happy now!

---

<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:** [5 June 2021 14:39 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/8 "2021-06-05T14:39:18Z")

</div>

> [@derko](#):
>
> But it is not that unusual wanting a specific time inserted into InfluxDB instead of the current time

More often when that is required there is a set of values to be written, with multiple timestamps, in which case the influx batch node is more efficient. You are right though, it would be worthwhile to include that in the help text, it may just be an oversight on the part of the author. You could raise an issue on the node's github page suggesting it is added, or even better fork the repository, improve the text, and submit a Pull Request.

---

<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:** [5 July 2021 14:39 UTC](https://discourse.nodered.org/t/specified-time-in-influx-object/46703/9 "2021-07-05T14:39:30Z")

</div>

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