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 (influxdata.com)
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
Hi Juan_Alonso_Pia
I am trying to use the evets.duration to count the number of days but I can only get zero. I have the follow code extract.
import “contrib/tomhollingworth/events”
from(bucket: “home”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> events.duration(unit: 1d)
This give the following
Any ideas why this giving 0 for duration?
Thanks
David
at least that first page seems to be ok, the difference between second _time entry and first _time entry is 0 days, same with the third entry and the second entry, the elapsed time was 0 days
because those _times were in the same day
thanks for the reply. I thought that the events.duration provides the number of periods between the first and last record? i.e. the dataset.
No, events duration gets the time between subsequent records. but there is a function for that, I just dont remember at the top of my mind.
Obtener Outlook para Android
Nvm i was thinking about spread() but it is to find the difference between min and max values, you could duplicate time, convert as int then use spread and convert the result to duration, but with all those steps maybe it will be easier just to get the cumulative sum of the result of events.duration()