# InfluxDB query with Python - time difference of 2h

**URL:** <https://community.influxdata.com/t/influxdb-query-with-python-time-difference-of-2h/32169>\
**Category:** InfluxDB 2\
**Tags:** influxdb, query, python, timestamp\
**Created:** [November 16, 2023, 8:01pm UTC](https://community.influxdata.com/t/influxdb-query-with-python-time-difference-of-2h/32169 "2023-11-16T20:01:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xtremdiver](https://avatars.discourse-cdn.com/v4/letter/x/858c86/32.png) [@Xtremdiver](https://community.influxdata.com/u/Xtremdiver)\
**Post date:** [November 16, 2023, 8:01pm UTC](https://community.influxdata.com/t/influxdb-query-with-python-time-difference-of-2h/32169/1 "2023-11-16T20:01:40Z")

</div>

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:

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

 ![2023-11-16_01-ResultChart](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/7/75c0986be6134b830f1fc990fa4b3bc70a88e22a.png)

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

```auto
from influxdb import InfluxDBClient
host = '192.168.555.555'
port=8086
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)
print(result)

```

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

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [November 20, 2023, 7:40am UTC](https://community.influxdata.com/t/influxdb-query-with-python-time-difference-of-2h/32169/2 "2023-11-20T07:40:09Z")

</div>

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](https://docs.influxdata.com/influxdb/cloud/query-data/influxql/explore-data/time-and-timezone/#:~:text=By%20default%2C%20InfluxDB%20stores%20and,or%20UTC%20DST%20to%20appear).  
Or see the reference to it here:  
[Time and timezone queries | InfluxDB Cloud (TSM) Documentation](https://docs.influxdata.com/influxdb/cloud/query-data/influxql/explore-data/time-and-timezone/#time-syntax)

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