Time seems off when writing to InfluxDB

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 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.

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

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

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.

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.

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

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.

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.

1 Like

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.

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