Calculate days between time series and today

Hi all,

I have a data series that includes the time in seconds:

I want to:

  1. use the most-recent captured data point
  2. THEN subtract the time()
  3. THEN divide by 86400 (to get number of days)
  4. THEN display the number of days

I can get (1) and (2) working, but I’m not sure how to add additional expressions to my query for (3). Can anyone point me in the right direction?

Query inspector currently set to:

Expr: date_expiry - time()
Step: 20s

Hi @gavinmckay,

Welcome to the :grafana: community support forums !!

Please review the submission template and include more details:

  • What Grafana version and what operating system are you using?
  • What is your datasource?
  • What visualization panel you are using e.g. time-series, bar chart, histogram etc?
  • What are you trying to achieve?
  • How are you trying to achieve it?
  • What happened?
  • What did you expect to happen?
  • Can you copy/paste the configuration(s) that you are having problems with?
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
  • Did you follow any online instructions? If so, what is the URL?

I am still early in testing but this looks like it is working for me to get the number of days in a time window.

declare @numdays INTEGER
set @numdays = DateDIFF(day, $__timeFrom(),$__timeTo())