InfluxDB and Grafana - Get today date on query editor

How do I get the start of the current day, using Grafana and InfluxDB?

I saw that Grafana uses “now/d” in the timerange to do this. But I need to get the current day in the query editor.

Screenshot_1

I tried this but it doesn’t work:

I also tested:

select mean(value) from MEDIDOR where time > now()/d group by time(1h) 
select mean(value) from MEDIDOR where time > now(d) group by time(1h) 
select mean(value) from MEDIDOR where time > $now/d group by time(1h) 
select mean(value) from MEDIDOR where time > $now(d) group by time(1h) 
select mean(value) from MEDIDOR where time > ${now/d} group by time(1h) 
select mean(value) from MEDIDOR where time > ${now(d)} group by time(1h) 

Perhaps I have misunderstood your question, but shouldn’t you write your InfluxQL query to use $timeFilter in the WHERE clause of the query so that it references the time selector, and then use Grafana’s dropdown for “Today so far”? In my screenshot below, I did this at 20:30:

1 Like

I use the time selector for others graphs on the same dashboard. What im trying to do is a label with the total of a value. Something like this:

Screenshot_1

What I need is the “today so far” option, but on my query. Thats why it needs to be independent of time selector. Something like:

select mean(value) from MEASUREMENT where time >= today_so_far

Just for kicks, try this in your SELECT query…

WHERE time > now()/d AND time <= now()
1 Like

Nope. The now()/d doesnt work.

now/d is not a macro, so it won’t be interpolated.

I would say the only way is to create dashboard variable which will calculate that value somehow, e. g. mysql/postgresql query and then use that variable in the influxql query.

1 Like

The only solution I found was to create a python script to do the calculation. Then I inserted it into an Influx database. I don’t know if it’s the best solution, but it works :sweat_smile: