InfluxDB query with Python - time difference of 2h

Hello dear community,

I found a discrepancy between the query within the Influx environment and via SQL query (with Python and the InfluxDBClient module) and I don’t know how to fix this.

I executed my query within the InfluxDB environment with the following query:

SELECT max("value") AS "kWh" FROM "kWh" WHERE time > '2023-09-14' AND time < '2023-09-15' AND "entity_id"='kwh' GROUP BY time(1h) FILL(previous) tz('Europe/Berlin');

This gives me the following chart.

I do the same query with Python. My Python script looks like this:

from influxdb import InfluxDBClient
host = '192.168.555.555'
username = 'myusername'
password = 'mypassword'
database = 'mydatabase'
client = InfluxDBClient(host, port, username, password, database)
query = 'SELECT max("value") AS "kWh" FROM "kWh" ' \
         'WHERE time > \'2023-09-14\' AND time < \'2023-09-15\' AND ' \
         '"entity_id"=\'kwh\' ' \
         'GROUP BY time(1h) FILL(previous) TZ(\'Europe/Berlin\')'
result = client.query(query)

As a result I get the following values
ResultSet({‘(‘kWh’, None)’: [
{‘time’: ‘2023-09-13T22:00:00Z’, ‘kWh’: 5280.34},
{‘time’: ‘2023-09-13T23:00:00Z’, ‘kWh’: 5280.62},
{‘time’: ‘2023-09-14T00:00:00Z’, ‘kWh’: 5280.87},
{‘time’: ‘2023-09-14T01:00:00Z’, ‘kWh’: 5281.14},
{‘time’: ‘2023-09-14T02:00:00Z’, ‘kWh’: 5281.4},
{‘time’: ‘2023-09-14T03:00:00Z’, ‘kWh’: 5281.69},
{‘time’: ‘2023-09-14T04:00:00Z’, ‘kWh’: 5282.11},
{‘time’: ‘2023-09-14T05:00:00Z’, ‘kWh’: 5282.99},
{‘time’: ‘2023-09-14T06:00:00Z’, ‘kWh’: 5283.24},
{‘time’: ‘2023-09-14T07:00:00Z’, ‘kWh’: 5283.58},
{‘time’: ‘2023-09-14T08:00:00Z’, ‘kWh’: 5285.93},
{‘time’: ‘2023-09-14T09:00:00Z’, ‘kWh’: 5290.0},
{‘time’: ‘2023-09-14T10:00:00Z’, ‘kWh’: 5299.79},
{‘time’: ‘2023-09-14T11:00:00Z’, ‘kWh’: 5310.36},
{‘time’: ‘2023-09-14T12:00:00Z’, ‘kWh’: 5321.31},
{‘time’: ‘2023-09-14T13:00:00Z’, ‘kWh’: 5331.86},
{‘time’: ‘2023-09-14T14:00:00Z’, ‘kWh’: 5340.38},
{‘time’: ‘2023-09-14T15:00:00Z’, ‘kWh’: 5346.83},
{‘time’: ‘2023-09-14T16:00:00Z’, ‘kWh’: 5349.8},
{‘time’: ‘2023-09-14T17:00:00Z’, ‘kWh’: 5350.27},
{‘time’: ‘2023-09-14T18:00:00Z’, ‘kWh’: 5350.95},
{‘time’: ‘2023-09-14T19:00:00Z’, ‘kWh’: 5352.1},
{‘time’: ‘2023-09-14T20:00:00Z’, ‘kWh’: 5352.68},
{‘time’: ‘2023-09-14T21:00:00Z’, ‘kWh’: 5353.15}

In the chart (query in the InfluxDB page) I get the same value for 12:00 as in the Python query for 10:00
Why do I get a time-shifted timestamp from InfluxDB?

Thanks a lot for your help.

Hello @Xtremdiver by default InfluxDB returns timestamps in UTC.
You can use Flux functins to change the timezone:
Time and timezone queries | InfluxDB Cloud (TSM) Documentation.
Or see the reference to it here:
Time and timezone queries | InfluxDB Cloud (TSM) Documentation

I’m assuming/hoping that’s probably what’s causing the difference. Let me know if that makes sense :slight_smile: