# Add duration ( seconds \> 2 digits ) to timestamp with ruby filter

**URL:** <https://discuss.elastic.co/t/add-duration-seconds-2-digits-to-timestamp-with-ruby-filter/164666>\
**Category:** Logstash\
**Created:** [January 17, 2019, 3:23pm UTC](https://discuss.elastic.co/t/add-duration-seconds-2-digits-to-timestamp-with-ruby-filter/164666 "2019-01-17T15:23:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isilve28](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@Isilve28](https://discuss.elastic.co/u/Isilve28)\
**Post date:** [January 17, 2019, 3:23pm UTC](https://discuss.elastic.co/t/add-duration-seconds-2-digits-to-timestamp-with-ruby-filter/164666/1 "2019-01-17T15:23:48Z")

</div>

Hi ,

I checked [this](https://discuss.elastic.co/t/increment-timestamp-with-a-float-field/131915) topic, [this](https://discuss.elastic.co/t/want-to-add-duration-in-seconds-to-timestamp/125003) one and also [this](https://discuss.elastic.co/t/ruby-error-in-adding-millisecond-to-timestamp-copy/145190/5) one and any of them resolved my problem.

I have start\_time and I want to add duration (in seconds) in order to get end\_time

I have duration in seconds like this : 5405,004 where 005 are milliseconds, and 5405 = 1 hour 30 minutes and 4 seconds.

I want to add them to start\_time : 2019-01-17T09:14:26.5553520Z

I tried methods mentionned above, and I don't get the result I want ( 2019-01-17T10:44:30.5593520Z ).

Any idea to resolve my problem ? Thanks in advance !

---

<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:** [January 17, 2019, 6:43pm UTC](https://discuss.elastic.co/t/add-duration-seconds-2-digits-to-timestamp-with-ruby-filter/164666/2 "2019-01-17T18:43:41Z")

</div>

You can parse the start\_time with a date filter using ISO8601. After using mutate+gsub to convert the , to . you can grok the duration into a float. Having done that the following will get you

```
              "end" => 2019-01-17T10:44:31.559Z,

ruby {
    code => '
        t = event.get("ts").to_s
        event.set("end", Time.at( Time.iso8601(t).to_f + event.get("duration_as_float") ) )
    '
}

```

Joda time operations are only accurate to the millisecond. If you want to keep the additional 4 digits of precision you could parse them off the start time, convert the end time back to a string and append them.

---

<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:** [February 14, 2019, 6:43pm UTC](https://discuss.elastic.co/t/add-duration-seconds-2-digits-to-timestamp-with-ruby-filter/164666/3 "2019-02-14T18:43:44Z")

</div>

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