# Logstash Ruby filter to subtract difference between two timestamps in single event

**URL:** https://discuss.elastic.co/t/logstash-ruby-filter-to-subtract-difference-between-two-timestamps-in-single-event/32580
**Category:** Logstash
**Created:** [October 20, 2015, 2:56pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-to-subtract-difference-between-two-timestamps-in-single-event/32580 "2015-10-20T14:56:35Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![cschotke](https://avatars.discourse-cdn.com/v4/letter/c/4da419/32.png) [@cschotke](https://discuss.elastic.co/u/cschotke)
#### Post date: [October 21, 2015, 3:59pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-to-subtract-difference-between-two-timestamps-in-single-event/32580/4 "2015-10-21T15:59:23Z")

</div>

I think you could just do something like:

```auto
ruby {
    init => "require 'time'"
    code => "event['time_difference'] = event['received_at'] - event['@timestamp'];"
}

```

---

_[View the full topic](https://discuss.elastic.co/t/logstash-ruby-filter-to-subtract-difference-between-two-timestamps-in-single-event/32580)._
