Taras Kinash
Taras Kinash

Reputation: 61

Configuring timezones in InfluxDB

I am experimenting with InfluxDB for timeseries datastore solution, and having an issue with using InfluxDB with different timezones.

Essentially, I am writing all data points into InfluxDB with UTC timestamps, but in the queries it would be very convenient (especially for testing) to specify timestamp ranges using the local timezone of the server.

Does anybody know how to achieve this in InfluxDB?

Upvotes: 5

Views: 24801

Answers (3)

Dan Dascalescu
Dan Dascalescu

Reputation: 151702

Given that displaying the time in a specified timezone isn't possible, I don't think it's possible to set the timezone for interpreting time values in queries either.

The best you can do is to specify the GMT offset in each time value, and also add the matching tz('...') at the end of the query, to display the time in the desired timezone.

SELECT * FROM measurement
  WHERE time >= '2020-01-10T23:45:56-04:00'
    AND time <  '2020-01-10T23:45:59-04:00'
tz('America/New_York')

Upvotes: 2

R wang
R wang

Reputation: 166

I living in the other end of the pacific ocean And I using python to put data into influxdb. Once,I was so desperate for the answer of your question.I gave up searching cuz the official did not provide the way to achieve this. So when I putting data into influxdb,I will decrease my timestamp by 28800. :) and when I need querying, I will do some compensation work like:

def fab_querytime(intime):
    if isinstance(intime,basestring) and len(intime) == 12:
    # my query time args like 201804061200
        _t = arrow.get(intime,'YYYYMMDDHHmm')
        _t = _t.replace(hours=-8)
        return fab_querytime(_t)
    if isinstance(intime,arrow.arrow.Arrow):
       _str = intime.format('YYYY-MM-DDTHH:mm:ss') + '.000Z'
        return str(_str)

Upvotes: 0

ezotrank
ezotrank

Reputation: 463

You can compute timezone before or after query to Influxdb by your side, another solutions I don't see. And btw, use everywhere utc timezone it's really good decision, and compute to time zone do you need only in last point.

Upvotes: 5

Related Questions