# Calculate of time in kibana

**URL:** https://discuss.elastic.co/t/calculate-of-time-in-kibana/132877
**Category:** Kibana
**Created:** [May 22, 2018, 6:41pm UTC](https://discuss.elastic.co/t/calculate-of-time-in-kibana/132877 "2018-05-22T18:41:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![iamlearner123](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@iamlearner123](https://discuss.elastic.co/u/iamlearner123)
#### Post date: [May 22, 2018, 6:41pm UTC](https://discuss.elastic.co/t/calculate-of-time-in-kibana/132877/1 "2018-05-22T18:41:10Z")

</div>

Hello,

I am learning kibana but i would like to know how to perform the subtraction. For example, we have two fields " **starting** = 2018-05-15 12:20:03.400779 , **ending** =2018-05-15 12:20:03.360979" . Can please know is there anyway to calculate **duration** (_ending - starting_) as a field. i am having hard to implement it as scripted field. Any help would be appreciated.

---

<div class="post-metadata">

### Author: ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)
#### Post date: [May 22, 2018, 7:01pm UTC](https://discuss.elastic.co/t/calculate-of-time-in-kibana/132877/2 "2018-05-22T19:01:48Z")

</div>

Yep, it can be done.  
If you have two date fields (time1 and time2) you can write a script like this:  
`doc['time2'].value - doc['time1'].value`

You'll also want to have the scripted field with  
type: **number**  
Format: **Duration**  
InputFormat: **seconds** (if you use the date fields as normal UNIX timestamp)  
OutputFormat: **Human Readable**

---

<div class="post-metadata">

### Author: ![iamlearner123](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@iamlearner123](https://discuss.elastic.co/u/iamlearner123)
#### Post date: [May 22, 2018, 7:53pm UTC](https://discuss.elastic.co/t/calculate-of-time-in-kibana/132877/3 "2018-05-22T19:53:08Z")

</div>

Thank you for the reply. when i tried the same thing as you mentioned above , i am getting an error " **15 out of 70 shards failed**" and kibana is not displaying any results.

---

<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 19, 2018, 7:53pm UTC](https://discuss.elastic.co/t/calculate-of-time-in-kibana/132877/4 "2018-06-19T19:53:12Z")

</div>

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