# Logstash date difference in minutes

**URL:** <https://discuss.elastic.co/t/logstash-date-difference-in-minutes/67243>\
**Category:** Logstash\
**Created:** [November 26, 2016, 3:49pm UTC](https://discuss.elastic.co/t/logstash-date-difference-in-minutes/67243 "2016-11-26T15:49:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dallas\_Toth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dallas_toth/32/22630_2.png) [@Dallas\_Toth](https://discuss.elastic.co/u/Dallas_Toth)\
**Post date:** [November 26, 2016, 3:49pm UTC](https://discuss.elastic.co/t/logstash-date-difference-in-minutes/67243/1 "2016-11-26T15:49:15Z")

</div>

I am looking for some direction on filters. I have a event with a startdatetime and enddatetime I need to add a field to the same event which is the difference in minutes. Elapse won't work since the startdatetime and enddatetime are in the same event. I need to add a new field called minutes that is a calculation of enddatetime - startdatetime.

---

<div class="post-metadata">

**Author:** ![Dallas\_Toth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dallas_toth/32/22630_2.png) [@Dallas\_Toth](https://discuss.elastic.co/u/Dallas_Toth)\
**Post date:** [November 26, 2016, 5:11pm UTC](https://discuss.elastic.co/t/logstash-date-difference-in-minutes/67243/2 "2016-11-26T17:11:19Z")

</div>

I figured it out. With a help from a post from @ottignon  
Thx

ruby {  
init =\> "require 'time'"  
code =\> "startdatetime = Time.iso8601(event['[records][start\_date]'].to\_s).to\_i;  
enddatetime = Time.iso8601(event['[records][end\_date]'].to\_s).to\_i;  
event['seconds'] = enddatetime - startdatetime;  
event['minutes'] = (enddatetime - startdatetime) / 60;  
event['hours'] = ((enddatetime - startdatetime) / 60) / 60;"  
}

---

<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:** [December 24, 2016, 5:11pm UTC](https://discuss.elastic.co/t/logstash-date-difference-in-minutes/67243/3 "2016-12-24T17:11:52Z")

</div>

Closed on December 24, 2016, 5:11pm UTC

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