# Time difference between two fields in a csv using ruby plugin

**URL:** <https://discuss.elastic.co/t/time-difference-between-two-fields-in-a-csv-using-ruby-plugin/122115>\
**Category:** Logstash\
**Created:** [March 1, 2018, 3:49pm UTC](https://discuss.elastic.co/t/time-difference-between-two-fields-in-a-csv-using-ruby-plugin/122115 "2018-03-01T15:49:23Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![donovans](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@donovans](https://discuss.elastic.co/u/donovans)\
**Post date:** [March 2, 2018, 10:51am UTC](https://discuss.elastic.co/t/time-difference-between-two-fields-in-a-csv-using-ruby-plugin/122115/4 "2018-03-02T10:51:40Z")

</div>

Hi Badger , The below seemed to work for me

```
ruby {
    init => "require 'time'"
    code => "
           starttime = Time.iso8601(event.get('CREATED').to_s).to_f;
           endtime = Time.iso8601(event.get('RESOLVED').to_s).to_f;
           event.set('time_diff', endtime - starttime);
            "
    add_tag => ["calculated_time_difference"]
  }

```

Thank you for your input 🙂

---

_[View the full topic](https://discuss.elastic.co/t/time-difference-between-two-fields-in-a-csv-using-ruby-plugin/122115)._
