Get time delta in InfluxQL

Hi everyone! Hope someone can advice, I struggling to create a InfluxQL query to receive time difference between now and last record but no luck so far. I have a query to receive last records but have no idea how to make a simple operation like “time - now” in select part.

My query for Grafana:

SELECT last("MinBid") as "last_tick", "time" - now as "t_delta"
FROM "gateway" 
WHERE $timeFilter GROUP BY "symbol"

If I use “now()” is returns me “InfluxDB Error: undefined function now()”.
“time” having format like this: 1680689272782

Is it actually possible to make such calculations with timestamps in Influxql?

(sadly) you can’t manipulate or calculate on the “time” using InfluxQL.

that said, you may still do something in another layer, the time is a numeric value (epoch nanosec), meaning you can still calculate your “elapsed” if you have the epoch of now()

1 Like