Time series and mysql problem with time zone

Hello, I’m facing an issue. I’m collecting data from a controller and visualizing it with Grafana. The controller sends data to MySQL in UTC, the server itself is set to UTC+1, and I’m accessing Grafana from a UTC+2 time zone. Grafana is generating the query

 SELECT 
 timestamp AS time,
 Flow_Concentrate,
 Flow_Permeate
FROM asedlt_8622.plc_data
 WHERE timestamp BETWEEN FROM_UNIXTIME(1744030193) AND FROM_UNIXTIME(1744030493)

I checked the dates I’m receiving on my server, and they are in UTC, so I’m converting the time accordingly.

FROM_UNIXTIME(1744030193)
2025-04-07 15:49:53
FROM_UNIXTIME(1744030493)
2025-04-07 15:54:53

I got data from 2025-04-07 15:49:53 to 2025-04-07 15:54:53. I don’t have such data in the database because it’s 3 hours behind.

If it’s possible, do you have a way to make Grafana generate the query like this?

SELECT 
timestamp AS time,
Flow_Concentrate,
Flow_Permeate
 FROM asedlt_8622.plc_data
 WHERE timestamp BETWEEN FROM_UNIXTIME(1744030193-**3600*3**)
 AND FROM_UNIXTIME(1744030493-**3600*3**)

Are there any other ways to reduce the query time? How does Grafana handle UTC time with $__timeFilter?

I read forum and fund one solution I tried and it working

SELECT 
  timestamp AS time,
  Flow_Concentrate,
  Flow_Permeate
FROM asedlt_8622.plc_data
WHERE timestamp BETWEEN FROM_UNIXTIME($__unixEpochFrom()-10800) 
AND FROM_UNIXTIME($__unixEpochTo()-10800)
ORDER BY timestamp;

but maybe somebody know another way?

Why you don’t fix your timezone issue instead of weird workaround?

That’s good start.

Now make sure user used by Grafana has UTC. Makes sure that dashboard/panel has set UTC timezone (for debugging - you will set desired timezone when everything is working properly in UTC first).

question how fix time zone problem :slight_smile:

Please read again:

For example:

If this query doesn’t return 0 (in the Grafana, not outside Grafana), then you can say that MySQL user used by Grafana is not querying in the UTC timezone. So you can have data in UTC, but Grafana will receive results in non-UTC (but it expects data in UTC). I’m not saying that this is your solution because you didn’t provide a reproducible example. But this is mandatory, and there can be many other variables, which can be misconfigured so I gave you some hints.