Count days from _time (or _value) to now

Hey needing your help again,

i want to know how many days have passed since the first database entry found. Currently i managed to get the _time of the value i was searching for but i couldn’t find out how to calculate the days.

This is my Table and my Query. All i want is a calculation which tells me how many days have passed since 8th of march. Can someone help me? I’m stuck since days

I was thinking about using duration() but couldnt get that to work either. If this works id like to display it in grafana which shouldnt be a problem. Calculation could also be done in grafana if that would work.
Thanks in advance!

Hello @Fernien,

There is a function called events.duration(), which basically calculates the time elapsed between a record and the subsequent record but, for the final record, it compares with the time that you indicate. In this way, if you only have one record and specify now(), you will get the number of days passed in a new column.

I leave you here with the page of the function:

events.duration() function | Flux 0.x Documentation (

This is a code example of the function for your case:

|> events.duration(
unit: 1d,
columnName: “duration”,
timeColumn: “_time”,
stopColumn: “_stop”,
stop: now()

And this is the output that you get. Notice the column ‘duration’ with the number of days passed by.

Let me know if this is what you were looking for.

1 Like

OMG Thank you so so much!!!
I spent soo much time trying different things but i seem to be to stupid for flux haha

Can’t thank you enough it works great!

No worries! Happy to help :grin: