# Can I convert a string column type to a timestamp?

**URL:** <https://discuss.elastic.co/t/can-i-convert-a-string-column-type-to-a-timestamp/316385>\
**Category:** Kibana\
**Created:** [October 11, 2022, 9:04pm UTC](https://discuss.elastic.co/t/can-i-convert-a-string-column-type-to-a-timestamp/316385 "2022-10-11T21:04:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wpm/32/110146_2.png) [@wpm](https://discuss.elastic.co/u/wpm)\
**Post date:** [October 11, 2022, 9:04pm UTC](https://discuss.elastic.co/t/can-i-convert-a-string-column-type-to-a-timestamp/316385/1 "2022-10-11T21:04:53Z")

</div>

I ingested a bunch of documents. They have a property "time" containing strings of the form "2015-01-20 07:52:05.013047". I let Elastic automatically detect the data types and it treated "time" as a string. The schema has it as a `keyword`. Now that the data is already in there, I want to change this column type `date`.

What is the easiest way to do this?

Can it be done in Kibana? If not is there a tutorial for doing it in the REST API? (I've gathered you have to reindex, so there are a couple of steps involved here. I'm also not sure if the [Reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) is what I need.)

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [October 12, 2022, 1:38pm UTC](https://discuss.elastic.co/t/can-i-convert-a-string-column-type-to-a-timestamp/316385/2 "2022-10-12T13:38:06Z")

</div>

Hi @wpm

I would recommend a runtime field which returns a `Date` with a value script like the following:

```auto
String datetime = doc['my_string_date_field'].value;
ZonedDateTime zdt = ZonedDateTime.parse(datetime);
emit(zdt.toInstant().toEpochMilli());

```

---

<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 9, 2022, 1:38pm UTC](https://discuss.elastic.co/t/can-i-convert-a-string-column-type-to-a-timestamp/316385/3 "2022-11-09T13:38:26Z")

</div>

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