# I do not get subtract dates and ruby logstash

**URL:** https://discuss.elastic.co/t/i-do-not-get-subtract-dates-and-ruby-logstash/46212
**Category:** Logstash
**Created:** [April 4, 2016, 8:05am UTC](https://discuss.elastic.co/t/i-do-not-get-subtract-dates-and-ruby-logstash/46212 "2016-04-04T08:05:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![olorasde](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olorasde/32/40103_2.png) [@olorasde](https://discuss.elastic.co/u/olorasde)
#### Post date: [April 4, 2016, 8:05am UTC](https://discuss.elastic.co/t/i-do-not-get-subtract-dates-and-ruby-logstash/46212/1 "2016-04-04T08:05:36Z")

</div>

Hello,

I'm trying to subtract two dates ISO 8601 type, to extract an XML plugin through the ruby. The goal is to get the difference in the form of an integer with which to operate later.

I am using the latest version of logstash, 2.2.2.

I tried several examples, but without success. This is the example that I think is the one that should work.

Example:

`ruby {code => "event['time_difference'] = Time.parse(DateTime.Parse('t_fin_etapa01')).to_i - Time.parse(DateTime.Parse('t_inicio_etapa01')).to_i"}`

Result:

**? [31mRuby exception occurred: undefined method `gsub '! for # \<DateTime: 0x441d4c76\> {: level =\>: error} ? [0m**

Any idea what I'm doing wrong?

Thanks in advance,

Regards!

---

<div class="post-metadata">

### Author: ![olorasde](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olorasde/32/40103_2.png) [@olorasde](https://discuss.elastic.co/u/olorasde)
#### Post date: [April 29, 2016, 12:07pm UTC](https://discuss.elastic.co/t/i-do-not-get-subtract-dates-and-ruby-logstash/46212/2 "2016-04-29T12:07:19Z")

</div>

At the end I resolved the problem by sending the information dates to a temporary index elasticsearch and processing them through a Java app (via the java API ) to generate a final index with subtraction of two dates in milliseconds .

Solve the problem, but really is not an optimal solution .

Someone knows another more direct way to do subtractions between dates come within an index ?

---

<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:00am UTC](https://discuss.elastic.co/t/i-do-not-get-subtract-dates-and-ruby-logstash/46212/3 "2017-07-06T05:00:00Z")

</div>


