# Logstash event @timestamp adjustment

**URL:** <https://discuss.elastic.co/t/logstash-event-timestamp-adjustment/203616>\
**Category:** Logstash\
**Created:** [October 15, 2019, 10:13am UTC](https://discuss.elastic.co/t/logstash-event-timestamp-adjustment/203616 "2019-10-15T10:13:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan\_Sabolowitsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stefan_sabolowitsch/32/48680_2.png) [@Stefan\_Sabolowitsch](https://discuss.elastic.co/u/Stefan_Sabolowitsch)\
**Post date:** [October 15, 2019, 10:13am UTC](https://discuss.elastic.co/t/logstash-event-timestamp-adjustment/203616/1 "2019-10-15T10:13:37Z")

</div>

Hi there,  
i want to calculate "event.start" from "event.end" and "event.duration", so a subtraction of "event.end" and "event.duration"

"event.end": "2019-10-15T07:34:14.000Z",  
"event.duration": 30, (sec.)

Thereafter, event.duration is to be converted into nanoseconds, ie multiplication \* 1000000000.  
I've looked at using the ruby plug in but my ruby knowledge is zero

My first attempt is this:

```

if !([event.duration] == 0) {
	mutate	{
		add_field => {"event.end" => "%{@timestamp}" }
			}
			ruby {
# init => "require 'time'"
# code => "
# diff = event.get('start_date') - event.get('end_date')
# event.set('timediff') = diff;
# "
						code => "event.set('event.duration', event.get('event.duration').to_i * 1000000000))"	
			}
		}

```

But get the following error message:

```

[2019-10-15T12:11:05,640][ERROR][org.logstash.Logstash] java.lang.IllegalStateException: Logstash stopped processing because of an error: (SyntaxError) (ruby filter code):2: syntax error, unexpected ')'
 event.set('event.duration', event.get('event.duration').to_i * 1000000000)) 
                                                                           ^

```

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [October 15, 2019, 2:50pm UTC](https://discuss.elastic.co/t/logstash-event-timestamp-adjustment/203616/2 "2019-10-15T14:50:22Z")

</div>

> [@Stefan\_Sabolowitsch](#):
>
> "event.set('event.duration', event.get('event.duration').to\_i \* 1000000000))"

Remove one of the ) at the end of the code option.

---

<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:** [November 12, 2019, 2:50pm UTC](https://discuss.elastic.co/t/logstash-event-timestamp-adjustment/203616/3 "2019-11-12T14:50:27Z")

</div>

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