# How to do time math in script field

**URL:** <https://discuss.elastic.co/t/how-to-do-time-math-in-script-field/226886>\
**Category:** Kibana\
**Created:** [April 7, 2020, 11:56am UTC](https://discuss.elastic.co/t/how-to-do-time-math-in-script-field/226886 "2020-04-07T11:56:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Echo\_yu](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@Echo\_yu](https://discuss.elastic.co/u/Echo_yu)\
**Post date:** [April 7, 2020, 11:56am UTC](https://discuss.elastic.co/t/how-to-do-time-math-in-script-field/226886/1 "2020-04-07T11:56:51Z")

</div>

Hi, I want to do some time math in script field of Kibana. Now I have a field called startdatetime with the data type of date, and a field called runtime with the data type of number, how can i sum them up and return a new field with the type of date? Please help me . Looking forward to your reply, THANKS!

---

<div class="post-metadata">

**Author:** ![Liza\_Katz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liza_katz/32/52358_2.png) [@Liza\_Katz](https://discuss.elastic.co/u/Liza_Katz)\
**Post date:** [April 7, 2020, 12:16pm UTC](https://discuss.elastic.co/t/how-to-do-time-math-in-script-field/226886/2 "2020-04-07T12:16:29Z")

</div>

Hi @Echo_yu

Painless easily supports such manipulations:  
Try using something like this in your scripted field:

`Instant.ofEpochMilli(doc['startdatetime'].value.getMillis() + doc['runtime'].value)`

Good luck,  
Liza  
`

---

<div class="post-metadata">

**Author:** ![Echo\_yu](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@Echo\_yu](https://discuss.elastic.co/u/Echo_yu)\
**Post date:** [April 7, 2020, 12:40pm UTC](https://discuss.elastic.co/t/how-to-do-time-math-in-script-field/226886/3 "2020-04-07T12:40:34Z")

</div>

It works correctly！Thank you so much！ 🥰

---

<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 5, 2020, 12:40pm UTC](https://discuss.elastic.co/t/how-to-do-time-math-in-script-field/226886/4 "2020-05-05T12:40:36Z")

</div>

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