# How to calculate timediff of two fields in the same event

**URL:** https://discuss.elastic.co/t/how-to-calculate-timediff-of-two-fields-in-the-same-event/106417
**Category:** Logstash
**Created:** [November 5, 2017, 11:09am UTC](https://discuss.elastic.co/t/how-to-calculate-timediff-of-two-fields-in-the-same-event/106417 "2017-11-05T11:09:02Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![Ganesh\_Venkataraman](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Ganesh\_Venkataraman](https://discuss.elastic.co/u/Ganesh_Venkataraman)
#### Post date: [November 6, 2017, 7:58am UTC](https://discuss.elastic.co/t/how-to-calculate-timediff-of-two-fields-in-the-same-event/106417/3 "2017-11-06T07:58:14Z")

</div>

I don't know ruby so found it very difficult. I have used below post to find the solution.

> [@Logstash Ruby filter to subtract difference between two timestamps in single event](https://discuss.elastic.co/t/logstash-ruby-filter-to-subtract-difference-between-two-timestamps-in-single-event/32580/4):
>
> I think you could just do something like: ruby { init =\> "require 'time'" code =\> "event['time\_difference'] = event['received\_at'] - event['@timestamp'];" }

---

_[View the full topic](https://discuss.elastic.co/t/how-to-calculate-timediff-of-two-fields-in-the-same-event/106417)._
