# Text field to convert as date and perform math Operation

**URL:** <https://discuss.elastic.co/t/text-field-to-convert-as-date-and-perform-math-operation/260785>\
**Category:** Kibana\
**Created:** [January 12, 2021, 5:23am UTC](https://discuss.elastic.co/t/text-field-to-convert-as-date-and-perform-math-operation/260785 "2021-01-12T05:23:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sathish22](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Sathish22](https://discuss.elastic.co/u/Sathish22)\
**Post date:** [January 12, 2021, 5:23am UTC](https://discuss.elastic.co/t/text-field-to-convert-as-date-and-perform-math-operation/260785/1 "2021-01-12T05:23:44Z")

</div>

Hi All,

I need to convert a text field to date data type and perform a math operation on it

something like this

| Process ID | Process Name | Start Time | End Time | Difference |
| --- | --- | --- | --- | --- |
| 1 | Process1 | 2021-01-12T13:16:20.19Z | 2021-01-12T13:16:25.16Z | Start Time-End Time |
| 2 | Process2 | 2021-01-12T13:20:20.19Z | 2021-01-12T13:21:20.15Z | Start Time-End Time |
| 3 | Process3 | 2021-01-12T13:21:25.19Z | 2021-01-12T13:21:40.16Z | Start Time-End Time |
| 4 | Process4 | 2021-01-12T13:21:20.15Z | 2021-01-12T13:21:35.15Z | Start Time-End Time |

Here the problem is StartTime and End time are Text data type

Please help me

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [January 12, 2021, 3:32pm UTC](https://discuss.elastic.co/t/text-field-to-convert-as-date-and-perform-math-operation/260785/2 "2021-01-12T15:32:36Z")

</div>

You need to use a painless script to do this, which can be done using Kibana or using an Elasticsearch ingest pipeline. There are _many_ examples of doing this on the painless docs for date manipulation: [https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-datetime.html](https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-datetime.html)

---

<div class="post-metadata">

**Author:** ![Sathish22](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Sathish22](https://discuss.elastic.co/u/Sathish22)\
**Post date:** [January 13, 2021, 8:21am UTC](https://discuss.elastic.co/t/text-field-to-convert-as-date-and-perform-math-operation/260785/3 "2021-01-13T08:21:01Z")

</div>

Thank you for your response

There are errors after creating painless Scripted field

PFB image, I used to convert text to date

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/0/4073e60a8536372f02bb364c49273e7724a0ec94.png)

but it didn't work, please help what should I give in script

and input is displaying as numbers but my input data is (2021-01-12T13:16:20.198Z) in text format

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [January 13, 2021, 2:40pm UTC](https://discuss.elastic.co/t/text-field-to-convert-as-date-and-perform-math-operation/260785/4 "2021-01-13T14:40:43Z")

</div>

What you're showing doesn't look right. The previous link that I sent gives you instructions on how to convert from the string representation of a date to number, by parsing the date. Dates are numeric in Elasticsearch, so you need to do this parsing.

---

<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 10, 2021, 2:40pm UTC](https://discuss.elastic.co/t/text-field-to-convert-as-date-and-perform-math-operation/260785/5 "2021-02-10T14:40:53Z")

</div>

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