Convert date field to age from now

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

1 Like

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 :frowning:

1 Like

can you do it when writing it to prometheus as I do not see any extensive date time functions like datediff