Set time range for relative time


I run grafana locally with docker using “docker run -d -p 3000:3000 --name=grafana grafana/grafana-oss”.

I added a timeseries panel and i want this panel to display all data from the last 4 months until yesterday. This time range shall be valid only for this panel, i.e. I don’t want to use the dashboard time range selection to change what is displayed.

In the panel editor I found “Query options” and “Relative time”. There I can enter something like “now-4M” to get the data for the last 4 months. Unfortunately the upper bound here is “now”. I tried entering “now-4M-1d” or “now-1d-4M” or editing the json of the dashboard with " “timeTo”: “now-1d”,". Unfortunately it didn’t work.

Does anybody know how to achieve this?

As a datasource I use a locally running mysql db.

Thanks in advance!

You can’t “stack” the minus operation. I think that you should try “now-4M/M” or “now-120d/d” for your case.

Another option is to simply ignore Grafana’s time options and use the time range directly on your mysql query, something like:

  yourtable t
  /* Greater or equal to the start of last month */ >= DATE_ADD(LAST_DAY(DATE_SUB(NOW(), INTERVAL 2 MONTH)), INTERVAL 1 DAY) and
  /* Smaller or equal than one month ago */ <= DATE_SUB(NOW(), INTERVAL 1 MONTH) 

Source of the mysql query above: datetime - MySQL select all rows from last month until (now() - 1 month), for comparative purposes - Stack Overflow

1 Like

Go to dashboard settings (the cog icon in your image) and there is an option there to Hide time picker

Then use the specific time picker you want using sql query as @isaqueprofeta laid out