# Converting time to milliseconds

**URL:** <https://discuss.elastic.co/t/converting-time-to-milliseconds/135183>\
**Category:** Logstash\
**Created:** [June 8, 2018, 5:26pm UTC](https://discuss.elastic.co/t/converting-time-to-milliseconds/135183 "2018-06-08T17:26:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandeepnarla22322](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sandeepnarla22322](https://discuss.elastic.co/u/sandeepnarla22322)\
**Post date:** [June 8, 2018, 5:26pm UTC](https://discuss.elastic.co/t/converting-time-to-milliseconds/135183/1 "2018-06-08T17:26:47Z")

</div>

converting 00:00:00.013 in to milliseconds

I used to dissect to get values and having trouble calculating the values

dissect {  
mapping =\> {  
"ExecuteTime" =\> %{hour}:%{minute}:%{second}.%{millisecond}"  
}  
}  
if [hour] and [minute] and [second] and [millisecond] {  
ruby {  
code =\> "event.get['timeInSeconds'] = event.get['hour']\*3600+event.get['minute']\*60+event.get['second']+event.get['millisecond']/1000"  
}  
}

thanks in advance can you help me converting data in milliseconds

---

<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:** [June 8, 2018, 5:50pm UTC](https://discuss.elastic.co/t/converting-time-to-milliseconds/135183/2 "2018-06-08T17:50:36Z")

</div>

You are missing a " in your dissect mapping, and you need to use event.get/set to get and add fields to the event.

```auto
    dissect {
        mapping => { "ExecuteTime" => "%{hour}:%{minute}:%{second}.%{millisecond}" }
    }
    if [hour] and [minute] and [second] and [millisecond] {
        ruby {
            code => "event.set( 'timeInSeconds', event.get('hour').to_i*3600 + event.get('minute').to_i*60 +
                                                event.get('second').to_i + event.get('millisecond').to_f/1000)"
        }
    }

```

---

<div class="post-metadata">

**Author:** ![sandeepnarla22322](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sandeepnarla22322](https://discuss.elastic.co/u/sandeepnarla22322)\
**Post date:** [June 8, 2018, 6:05pm UTC](https://discuss.elastic.co/t/converting-time-to-milliseconds/135183/3 "2018-06-08T18:05:52Z")

</div>

Thanks @Badger you saved my day

than

---

<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:** [July 6, 2018, 6:05pm UTC](https://discuss.elastic.co/t/converting-time-to-milliseconds/135183/4 "2018-07-06T18:05:53Z")

</div>

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