Grafana InfluxDB UTC wrong date around midnight

Hello,

I am using Grafana v10.4.1 (d3ce857c0e) on Windows.

I have an DateTime problem.

In my Database I have values like:

2024.07.07 23.00.00.000Z
2024 07.08 02.00.00.000Z

In Grafana the setting for Timezone in Browsertime (UTC+2 right now).

When I read the data from my db, it is displayed like this:

2024.07.08.01.00.00.000 (UTC+2)
2024.07.08 03.00.00.000 (UTC+2)

This is somewhat ok, because it is the correct time and date.
But when I group by date in the query, these timestamps are on two different dates in UTC,
and not correctly grouped for my purpose.

How to get around this? I dont want to save in localtime, because… yeah… daylightsaving.

Thank you!

1 Like

That’s correct. InfluxDB groups in UTC by default. There is option to set timezone on the InfluxDB query level, but then Grafana will be confused, because it expects data in UTC (so remove set Grafana dashboard to UTC, so Grafana won’t be “moving” received data, which are already in local timezone to your browser timezone)

Yes, I know. That is what I concluded.
The question was more of a type: how to get around this easily.

I thougt about the timezone offet in the query, and to transform it back maybe in grafana. But it feels so wrong, and I should not be the only one with the problem.

Maybe I will fetch all data first, and will then sort, but I will lose so many things like give me the first or last entry of a day directly in the query.

make sure your data saves dates as utc or a function that converts the date time to utc when querying

the latter is not preferred

Correct, so your InfluxDB options:

  • use offset in the query - group in non UTC timezone and you will have daylightsaving issues (it depends on implementation in InfluxDB, but I don’t think there is a perfect solution) + confussion on the Grafana side (e. g. which timezone)
  • don’t use offset - group in UTC and then have mentioned problems from the initial post

You may try to query raw data (with/without offset) and then try some transformations (time grouping if it’s available) - that can be very slow, especially if you have a lot records to proccess.

Another (crazy) idea - store local day as a label on the record level and then group by that label. :person_shrugging:

Thanks for your ideas, that are the same trians of thought that I had.
The good thing is: I create the data, so I can do everything I need to do to get the desired results.

I will play a little bit with my data, and will see what will happen.

Thank you all!

2 Likes