0

I want to query my records from today at 00.00 to now(). The problem is that I want to do this dynamically so I need to manipulate the timestamp using now() function.

Here is the query as an example.

SELECT SUM("something")
FROM "any_table_whatsoever"
WHERE time >= (now() - (now() % 86400) - (now() % 3600))

Here is the response.

error parsing query: found %, expected ) at line 3, char 29

It seems InfluxQL doesn't support modulo over timestamp. I also think that's I might treat it wrongs. For your information, I'm using InfluxQL on Grafana.

Are there any alternatives to achieve this?

EDIT: My Grafana panel must not relying on both $timeFilter and $__interval. I mean, like, displaying a stats "so far today". That wouldn't work if I relying on such variables since when we change the interval on Grafana, the query would affected.

wisn
  • 974
  • 10
  • 17

1 Answers1

0

You don't need to calculate it. Grafana has a predefined time range for that Today so far, which will calculate times for the query automatically: Grafana

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
  • My panel must display the result as I stated above. That's means my query must not relying on Grafana's predefined time range – wisn Jan 17 '19 at 13:32
  • 1
    Then you should remove tag Grafana because you need pure InfluxDB solution. – Jan Garaj Jan 17 '19 at 17:10
  • Removed. Thank you for your answer anyway – wisn Jan 17 '19 at 23:30
  • `time >= (now() - (now() % 86400) - (now() % 3600))` seem to always resolve to a time frame which is somewhat close to the current time. What sort of time range are you trying to achieve here? I think what @JanGaraj may work for you. – Samuel Toh Jan 18 '19 at 00:36
  • @SamuelToh I have edited my question. The point is I need a "dynamic" time range from `00:00` on that day until current time. Using Grafana's predefined time wouldn't do it since when I updated the interval, my query would affected. EDIT: As an example, today `00:00` until current time I edited this comment `09:21`. – wisn Jan 18 '19 at 02:21
  • My understanding is Grafana's time range is dynamic. When you build a dashboard saying "last 24 hours" this pre-defined time do not stop there as is, it moves. Maybe I didn't understand your question. – Samuel Toh Jan 18 '19 at 02:29