# Calculate elapsed time in Kibana?

**URL:** <https://discuss.elastic.co/t/calculate-elapsed-time-in-kibana/316575>\
**Category:** Kibana\
**Created:** [October 13, 2022, 7:56pm UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-kibana/316575 "2022-10-13T19:56:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TXBigDawg1836](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@TXBigDawg1836](https://discuss.elastic.co/u/TXBigDawg1836)\
**Post date:** [October 13, 2022, 7:56pm UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-kibana/316575/1 "2022-10-13T19:56:06Z")

</div>

ELK newbie here. Is it possible in Kibana visualization (ie. Table) to calculate the elapsed time from the timestamp and current time? Looking to populate a field in the table to show the elapsed time since the last timestamp received for specific messages.

Thanks!

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [October 13, 2022, 8:35pm UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-kibana/316575/2 "2022-10-13T20:35:11Z")

</div>

Hi @TXBigDawg1836 Welcome to the community

Yup add a runtime field to the Data View

here is the code

```auto
long datenow = new Date().getTime();
long datewas = doc['@timestamp'].value.getMillis();
emit (datenow - datewas);

```

Create / Set the Field

 ![Screen Shot 2022-10-13 at 1.23.42 PM](https://us1.discourse-cdn.com/elastic/original/3X/5/d/5d4e39d84e0916b69d05e71e5ff9fc6f12af9677.jpeg)

Chose your format....

 ![Screen Shot 2022-10-13 at 1.23.54 PM](https://us1.discourse-cdn.com/elastic/original/3X/d/6/d639a357175496391ed02c46c4a651d556eb7247.png)

In Discover

 ![Screen Shot 2022-10-13 at 1.34.19 PM](https://us1.discourse-cdn.com/elastic/original/3X/8/e/8e1a8f1a08a42c9ad880294e548ee361763cac18.jpeg)

Now Table...

 ![Screen Shot 2022-10-13 at 1.26.49 PM](https://us1.discourse-cdn.com/elastic/original/3X/d/f/dfde664fb2d3fdd19abf952fec49aee001218867.png)

---

<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 10, 2022, 4:39pm UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-kibana/316575/3 "2022-11-10T16:39:37Z")

</div>



---

<div class="post-metadata">

**Author:** ![TXBigDawg1836](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@TXBigDawg1836](https://discuss.elastic.co/u/TXBigDawg1836)\
**Post date:** [November 13, 2022, 10:18am UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-kibana/316575/4 "2022-11-13T10:18:15Z")

</div>

Stephen,  
Thanks for the detailed info. That was exactly what was needed and worked perfectly!

---

<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:** [December 11, 2022, 10:18am UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-kibana/316575/5 "2022-12-11T10:18:30Z")

</div>

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