# Calculate total time of a list of documents

**URL:** <https://discuss.elastic.co/t/calculate-total-time-of-a-list-of-documents/293280>\
**Category:** Kibana\
**Created:** [January 1, 2022, 8:05pm UTC](https://discuss.elastic.co/t/calculate-total-time-of-a-list-of-documents/293280 "2022-01-01T20:05:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![javidr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javidr/32/136982_2.png) [@javidr](https://discuss.elastic.co/u/javidr)\
**Post date:** [January 1, 2022, 8:05pm UTC](https://discuss.elastic.co/t/calculate-total-time-of-a-list-of-documents/293280/1 "2022-01-01T20:05:53Z")

</div>

Hi

I have some documents with a field called "duration", in the format HH:MM:SS. I would like to calculate the sum of the duration of the documents i have filtered by a date. However, when trying to sum the data, since it is not a numeric field it is not displayed in the field list

What can i do to sum some date fields?

Thanks

---

<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:** [January 3, 2022, 3:09pm UTC](https://discuss.elastic.co/t/calculate-total-time-of-a-list-of-documents/293280/2 "2022-01-03T15:09:24Z")

</div>

Hi @javidr,

I think you could make use of a runtime field for this use case:

- define a new runtime field as `duration_in_seconds` which emits the current `duration` value as seconds number

For instance something like this may work:

```auto
emit(
    doc['duration'].value.toInstant().atZone(ZoneOffset.UTC).toEpochSecond()
);

```

- as for the runtime field format pick the `Duration` option and set `seconds` as input:

 ![Screenshot 2022-01-03 at 16.07.29](https://us1.discourse-cdn.com/elastic/original/3X/e/8/e88aa454f4815386575ee72294603112a93fa4f8.png)

This will make you able to perform math with the `duration_in_seconds` field and the resulting value in the table/visualization will be something like the initial field one.

---

<div class="post-metadata">

**Author:** ![javidr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javidr/32/136982_2.png) [@javidr](https://discuss.elastic.co/u/javidr)\
**Post date:** [January 3, 2022, 6:41pm UTC](https://discuss.elastic.co/t/calculate-total-time-of-a-list-of-documents/293280/3 "2022-01-03T18:41:24Z")

</div>

yeah but it will not be displayed as a HH:MM:SS field. It is, if i have two documents, with 3600 and 3601 seconds, i want to display 02:00:01

Thanks

---

<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:** [January 4, 2022, 9:15am UTC](https://discuss.elastic.co/t/calculate-total-time-of-a-list-of-documents/293280/4 "2022-01-04T09:15:30Z")

</div>

Choosing the `number` format you can leverage the `Numerals.js` formats to have exactly that format:

 ![Screenshot 2022-01-04 at 10.14.44](https://us1.discourse-cdn.com/elastic/original/3X/d/a/da0c612384a7500b6282678db9100b88db1710e7.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:** [February 1, 2022, 9:15am UTC](https://discuss.elastic.co/t/calculate-total-time-of-a-list-of-documents/293280/5 "2022-02-01T09:15:58Z")

</div>

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