# How to convert nanoseconds to milliseconds

**URL:** <https://discuss.elastic.co/t/how-to-convert-nanoseconds-to-milliseconds/131895>\
**Category:** Logstash\
**Created:** [May 15, 2018, 9:38am UTC](https://discuss.elastic.co/t/how-to-convert-nanoseconds-to-milliseconds/131895 "2018-05-15T09:38:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevebeattie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevebeattie/32/9228_2.png) [@stevebeattie](https://discuss.elastic.co/u/stevebeattie)\
**Post date:** [May 15, 2018, 9:38am UTC](https://discuss.elastic.co/t/how-to-convert-nanoseconds-to-milliseconds/131895/1 "2018-05-15T09:38:16Z")

</div>

Hi,  
I have a timestamp as nanoseconds in an access log that I want to store in ES. I understand that the timestamp in ES is stored as milliseconds and that I'll need to convert. Will I have to use mutate and gsub to trim the last six digits from my nanoseconds timestamp? If so how would I go about that?

Thanks, Steve.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [May 15, 2018, 9:40am UTC](https://discuss.elastic.co/t/how-to-convert-nanoseconds-to-milliseconds/131895/2 "2018-05-15T09:40:22Z")

</div>

You should be able to use a mutate filter,

```nohighlight
mutate {
    gsub => ["fieldname", "\d{6}$", ""]
}

```

or a ruby filter if you want actual arithmetics.

---

<div class="post-metadata">

**Author:** ![stevebeattie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevebeattie/32/9228_2.png) [@stevebeattie](https://discuss.elastic.co/u/stevebeattie)\
**Post date:** [May 15, 2018, 11:56am UTC](https://discuss.elastic.co/t/how-to-convert-nanoseconds-to-milliseconds/131895/3 "2018-05-15T11:56:40Z")

</div>

Many thanks @magnusbaeck that's exactly what I was looking for.

Thanks, Steve.

---

<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:** [June 12, 2018, 12:03pm UTC](https://discuss.elastic.co/t/how-to-convert-nanoseconds-to-milliseconds/131895/4 "2018-06-12T12:03:20Z")

</div>

Closed on June 12, 2018, 12:03pm UTC

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