# Logstash issue

**URL:** <https://discuss.elastic.co/t/logstash-issue/325414>\
**Category:** Logstash\
**Created:** [February 13, 2023, 5:06pm UTC](https://discuss.elastic.co/t/logstash-issue/325414 "2023-02-13T17:06:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![namdev](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@namdev](https://discuss.elastic.co/u/namdev)\
**Post date:** [February 13, 2023, 5:06pm UTC](https://discuss.elastic.co/t/logstash-issue/325414/1 "2023-02-13T17:06:07Z")

</div>

Hi , I am new to elk stack,I want to create a new field which is the difference between two dates field.  
I want to do it in logstash.  
The two dates field data is given.  
I am using filter like this but not getting the output.

```auto
date {
            match => ["Start Date", "ISO8601"]
            target => "start_date"
        }
        date {
            match => ["End Date", "ISO8601"]
            target => "end_date"
        }
        

ruby {
      init => "require 'time'"
      code => "
        diff = event.get('start_date') - event.get('end_date')event.set('timediff') 
        "
      add_field => ["calculated_time_difference"]
    }

```

Any help would be appreciated

Thanks in advance !

---

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [February 14, 2023, 10:00am UTC](https://discuss.elastic.co/t/logstash-issue/325414/2 "2023-02-14T10:00:44Z")

</div>

```auto
  ruby {
    code => " event.set('diff', event.get('end_date').to_f - event.get('start_date').to_f ) "
  }

```

---

<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:** [March 14, 2023, 10:01am UTC](https://discuss.elastic.co/t/logstash-issue/325414/3 "2023-03-14T10:01:36Z")

</div>

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