influxdata / docs-v2

InfluxData Documentation that covers InfluxDB Cloud, InfluxDB OSS 2.x, InfluxDB OSS 1.x, InfluxDB Enterprise, Telegraf, Chronograf, Kapacitor, and Flux.
https://docs.influxdata.com
MIT License
69 stars 260 forks source link

Document SQL timezone support #5431

Closed sanderson closed 2 months ago

sanderson commented 3 months ago

The InfluxDB v3 SQL implementation lets you adjust timestamps at query time using the AT TIME ZONE operation. This takes a tz string as an argument and applies it to the preceding timezone. It's a bit verbose to use, but it works.

SELECT
  time AT TIME ZONE 'America/Los_Angeles' AS time,
  temp
FROM
  home
WHERE
  time >= ('2022-01-01T09:00:00Z' AT TIME ZONE 'America/Los_Angeles')

or

SELECT
  time AT TIME ZONE 'America/Los_Angeles' AS time,
  temp
FROM
  home
WHERE
  time >= (now() AT TIME ZONE 'America/Los_Angeles') - INTERVAL '30 days'