# Converting a string date (epoch) to a Date field using scripted fields in kibana

**URL:** <https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013>\
**Category:** Kibana\
**Created:** [March 19, 2019, 4:28pm UTC](https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013 "2019-03-19T16:28:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Katherinne\_Quintero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/katherinne_quintero/32/42348_2.png) [@Katherinne\_Quintero](https://discuss.elastic.co/u/Katherinne_Quintero)\
**Post date:** [March 19, 2019, 4:28pm UTC](https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013/1 "2019-03-19T16:28:03Z")

</div>

Hi!

I have a date in the form of a `string` (epoch) like below:

"1553012442470"

Now I want to use scripted fields in `kibana` to convert the string date time to a `date` field.

Also perform multiple operations with the field on the date, for example, subtract these two dates and choose the days of difference

How can I go about it?

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [March 20, 2019, 3:24pm UTC](https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013/2 "2019-03-20T15:24:30Z")

</div>

Is there any reason you wouldn't want to do this at ingest time instead of after the fact with a scripted field?

---

<div class="post-metadata">

**Author:** ![Katherinne\_Quintero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/katherinne_quintero/32/42348_2.png) [@Katherinne\_Quintero](https://discuss.elastic.co/u/Katherinne_Quintero)\
**Post date:** [March 21, 2019, 8:08pm UTC](https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013/3 "2019-03-21T20:08:21Z")

</div>

Lukas,  
When indexing the data we indicate the date Epoch is the \_id  
I can not reindex the data and change the mapping

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [March 22, 2019, 8:55pm UTC](https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013/4 "2019-03-22T20:55:22Z")

</div>

```auto
return new Date(Long.parseLong(doc["_id.keyword"].value));

```

---

<div class="post-metadata">

**Author:** ![Katherinne\_Quintero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/katherinne_quintero/32/42348_2.png) [@Katherinne\_Quintero](https://discuss.elastic.co/u/Katherinne_Quintero)\
**Post date:** [April 10, 2019, 5:24pm UTC](https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013/5 "2019-04-10T17:24:05Z")

</div>

Thanks Lukas! :sonriendo:

---

<div class="post-metadata">

**Author:** ![Katherinne\_Quintero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/katherinne_quintero/32/42348_2.png) [@Katherinne\_Quintero](https://discuss.elastic.co/u/Katherinne_Quintero)\
**Post date:** [April 10, 2019, 5:26pm UTC](https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013/6 "2019-04-10T17:26:04Z")

</div>

Thanks Lukas! :sonriendo:

---

<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:** [May 8, 2019, 5:26pm UTC](https://discuss.elastic.co/t/converting-a-string-date-epoch-to-a-date-field-using-scripted-fields-in-kibana/173013/7 "2019-05-08T17:26:05Z")

</div>

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