# Time seems off when writing to InfluxDB

**URL:** <https://discourse.nodered.org/t/time-seems-off-when-writing-to-influxdb/76072>\
**Category:** General\
**Created:** [3 March 2023 17:17 UTC](https://discourse.nodered.org/t/time-seems-off-when-writing-to-influxdb/76072 "2023-03-03T17:17:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NewToNodeRed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/newtonodered/32/76711_2.png) [@NewToNodeRed](https://discourse.nodered.org/u/NewToNodeRed)\
**Post date:** [3 March 2023 17:17 UTC](https://discourse.nodered.org/t/time-seems-off-when-writing-to-influxdb/76072/1 "2023-03-03T17:17:42Z")

</div>

I have code in Node Red writing the high and low temp for the each day at 11:59pm CST.

Node Red triggers at 2023-03-02 23:59pm CST.  
When I query influx it shows the time as 1677823140034645235, or 2023-03-03T05:59:00.034645235Z

Grafana then showed the data point as 2023-03-03T05:59:00

I deleted that line and did an insert of the data with a time of 1677823140000000000 (which I converted 2023-03-02 23:59 CST on this site: [https://www.epochconverter.com](https://www.epochconverter.com) to UTC time for the insert) but it is now 2023-03-03T05:59:00Z in the DB. And Grafana reads: 2023-03-02 18:00:00.

I know it is something with the time zone possibly but what do I need to adjust so I can write my data as close to midnight as possible and still get the datapoint on the correct date? I tried waiting and passing the time I wanted for the DB add but could not get my variable to go for the time column. In case it matters my time zone is CST (which is -6).

In case it matters for this measurement table all I care about is year and date, not time really at all. so if that could make for an easier solution at all. But I do not want to lose that precision on other measurements in the DB.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 March 2023 18:37 UTC](https://discourse.nodered.org/t/time-seems-off-when-writing-to-influxdb/76072/2 "2023-03-03T18:37:00Z")

</div>

> [@NewToNodeRed](#):
>
> Node Red triggers at 2023-03-02 23:59pm CST.  
> When I query influx it shows the time as 1677823140034645235, or 2023-03-03T05:59:00.034645235Z

That part is correct of course. The difference between CST and "Zulu" time, aka UTC, aka GMT.

> [@NewToNodeRed](#):
>
> Grafana then showed the data point as 2023-03-03T05:59:00

And that is "correct" in the sense that it is still showing UTC.

> [@NewToNodeRed](#):
>
> now 2023-03-03T05:59:00Z in the DB

As it should be. Always store and calculate on dates in UTC, it will save you loads of grief in the long run. You only want to get data from users and display to users in local time, always store in UTC.

> [@NewToNodeRed](#):
>
> And Grafana reads: 2023-03-02 18:00:00.

OK, so that's a bit odd. It is, of course UTC-12 so something has doubled the offset.

First thing to check is the `tz` setting on your server. Make sure it is set to your correct timezone. Then also check your browser/OS for the same. I'm pretty sure that Grafana should do the right thing. After all, most of us change "timezone" twice a year for DST. But I may be wrong, I'll admit I've not checked recently.

> [@NewToNodeRed](#):
>
> I know it is something with the time zone possibly but what do I need to adjust so I can write my data as close to midnight as possible and still get the datapoint on the correct date?

Which midnight? Your local one or UTC's? It depends on what you are trying to calculate.

> [@NewToNodeRed](#):
>
> In case it matters for this measurement table all I care about is year and date, not time really at all. so if that could make for an easier solution at all. But I do not want to lose that precision on other measurements in the DB.

The joy of InfluxDB is that you just send when you need to and then you get it to work out the hard stuff. So, for example, if you send only 1 value per 24hrs, you will still store the detailed timestamp but your query will either sum or average to 24hrs depending on what you are trying to achieve. Grafana makes that easier by working out the query for you. But you still need to know what you need to calculate.

---

<div class="post-metadata">

**Author:** ![NewToNodeRed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/newtonodered/32/76711_2.png) [@NewToNodeRed](https://discourse.nodered.org/u/NewToNodeRed)\
**Post date:** [3 March 2023 20:33 UTC](https://discourse.nodered.org/t/time-seems-off-when-writing-to-influxdb/76072/3 "2023-03-03T20:33:05Z")

</div>

I found some setting in Grafana, group by that I am playing with now to see what they do. Will need to see what happens tonight when the code writes. Will report back in a couple of days.

---

<div class="post-metadata">

**Author:** ![NewToNodeRed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/newtonodered/32/76711_2.png) [@NewToNodeRed](https://discourse.nodered.org/u/NewToNodeRed)\
**Post date:** [1 April 2023 04:53 UTC](https://discourse.nodered.org/t/time-seems-off-when-writing-to-influxdb/76072/4 "2023-04-01T04:53:40Z")

</div>

Sorry for the delay on follow up but that was the issue. A group by part in grafana was not giving me the granularity that i desired. Took that out of the query and now get the expected data results.

---

<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:** [31 May 2023 04:54 UTC](https://discourse.nodered.org/t/time-seems-off-when-writing-to-influxdb/76072/5 "2023-05-31T04:54:17Z")

</div>

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