How change the format of duration between two dates in dateTime?

I calculate the difference between two dates with this code.
ruby{
code => "event.set('Duration', (event.get('Release_date') - event.get('Date_of_entry')))"
}

the output that i have : field duration with type number like this: 18000
how can i get the difference in time HH:mm:ss ??
please any ideas??

You could do that using a ruby filter. See this post for some ideas.

Sorry, Maybe this question will be stupid but really i don't know how to use or add this code to my logstash file config and i must calculate the duration between two events (type date) ??can you help me please?

time_difference = current_time - old_time

def seconds_fraction_to_time(time_difference)
days = hours = mins = 0
mins = (seconds / 60).to_i
seconds = (seconds % 60 ).to_i
hours = (mins / 60).to_i
mins = (mins % 60).to_i
days = (hours / 24).to_i
hours = (hours % 24).to_i
return [days,hours,mins,seconds]
end

then you can print it out what ever way you wish,

if(days > 0)
return "#{days} Days #{hours} Hours"
else
return "#{hours} Hours #{mins} Minutes"
end

The documentation shows how to call code in a ruby filter.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.