Hello,
I am new to Grafana, and i would like to know if i can get Yesterday Date from a variable.
I am using ${__from:date} on a Dashboard with Infinity API JSON Request with a Body Content of:
{“BusinessDay”:“${__from:date:YYYY-MM-DD}”}
With that variable I am getting the today date, so I would like to find a way to get yesterday date.
Thanks in advance,
Andreas
Unfortunately, there is no way to directly perform math on variables like this (subtract a day from ${__from:date}
. But there are two remaining options:
-
Define a new TextBox variable for your dashboard called “yesterday” and enter the value in manually as text at the top of your dashboard. This will let you refer to
${yesterday}
if you wish, or in your case, you might choose to call it${RelevantBusinessDay}
. -
Define a new Query variable, and use an external data source to do the computation for you. For example if you use Postgres, you can get yesterday’s date using a SQL query such as
SELECT current_date - INTEGER '1' AS yesterday_date;
. In this way, you can use an existing data source you have to “fetch yesterday” and then define that as the${yesterday}
variable for your dashboard.
To see how to set up custom variables like that, check these docs: