# How to calculate difference between two dates and add to index

**URL:** <https://discuss.elastic.co/t/how-to-calculate-difference-between-two-dates-and-add-to-index/24628>\
**Category:** Logstash\
**Created:** [June 30, 2015, 1:40pm UTC](https://discuss.elastic.co/t/how-to-calculate-difference-between-two-dates-and-add-to-index/24628 "2015-06-30T13:40:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeroenvdV](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@JeroenvdV](https://discuss.elastic.co/u/JeroenvdV)\
**Post date:** [June 30, 2015, 1:40pm UTC](https://discuss.elastic.co/t/how-to-calculate-difference-between-two-dates-and-add-to-index/24628/1 "2015-06-30T13:40:33Z")

</div>

I have a log file and each entry contains multiple dates (when a ticket was opened, assigned, closed). Can I calculate the time passed with logstash and then add this value to each entry?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 30, 2015, 8:02pm UTC](https://discuss.elastic.co/t/how-to-calculate-difference-between-two-dates-and-add-to-index/24628/2 "2015-06-30T20:02:44Z")

</div>

Yes, but I suspect you'll have to write some custom Ruby code in a [ruby filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.html).

---

<div class="post-metadata">

**Author:** ![wajahat\_Javaid](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@wajahat\_Javaid](https://discuss.elastic.co/u/wajahat_Javaid)\
**Post date:** [July 28, 2015, 8:24am UTC](https://discuss.elastic.co/t/how-to-calculate-difference-between-two-dates-and-add-to-index/24628/3 "2015-07-28T08:24:17Z")

</div>

Hi, I have a similar use case, I just wanted to know if someone was able to solve this problem.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 5:33am UTC](https://discuss.elastic.co/t/how-to-calculate-difference-between-two-dates-and-add-to-index/24628/4 "2017-07-06T05:33:39Z")

</div>

Closed on July 6, 2017, 5:33am UTC


