I have a dahsboard with table having one column of type date (YYYY-MM-DD), i want to add another column with age in days from today. Basically subtract that date from today and calculate number of days. How can I do that?
Thanks
-M
That is really not a grafana related issue but more of sql query issue
But that said what is your data source? Mysql, postgres?
It is just prometheus query on Grafan 8.4.5
my data looks like:
metric-a{name=“xxxx”, create_date=“YYYY-MM-DD”} x
I can get that on Grafana dashboard as table with Name, Create_date columns, but i really need third column showing age (today - create_date), so that i can color rows which have age over 180 days etc
So really need date comparison, in the transformation i have reduce or binary operation and no date operation…
-M
Oops sorry. Wouls binary operation transformation do the job? But you would need a today variable. Not sure if grafana has a today variable
Well, I added today to my prometheus data, but if I do binary difference on two time fields, i get milliseconds back, so then i need to add another transformation to devide by 86400000 to get days, on top, i need to display all intermediate columns then only i can see final age column
can you do it when writing it to prometheus as I do not see any extensive date time functions like datediff
I just came across to your post. I don’t know if you still need this but for future reference.
If you use a table dashboard and one of your columns returns date:
- Under Override create new entry.
- Select “Fields with name” and select the column that displays the date.
- Add override property, select “Standard options > Units” and then “From Now”
This in turn change the column content to this view
To add an “Age Calculator” column, subtract the date column from today using SQL or your dashboard’s formula feature. For SQL, use: DATEDIFF(CURDATE(), date_column)
. This will give you the age in days.