# Calculate the time that passed between the insertion of one record and another

**URL:** <https://discuss.elastic.co/t/calculate-the-time-that-passed-between-the-insertion-of-one-record-and-another/221334>\
**Category:** Kibana\
**Created:** [February 27, 2020, 10:20pm UTC](https://discuss.elastic.co/t/calculate-the-time-that-passed-between-the-insertion-of-one-record-and-another/221334 "2020-02-27T22:20:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yorman\_steven\_ladino](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yorman_steven_ladino/32/63485_2.png) [@yorman\_steven\_ladino](https://discuss.elastic.co/u/yorman_steven_ladino)\
**Post date:** [February 27, 2020, 10:20pm UTC](https://discuss.elastic.co/t/calculate-the-time-that-passed-between-the-insertion-of-one-record-and-another/221334/1 "2020-02-27T22:20:27Z")

</div>

Hi, I need your help.

I need to calculate the time that passed between the insertion of one record and another.

Example

I insert a record that tells me the creation of a shift, and after x time I enter a new record with the end of a shift. I need to calculate the time that passed between the creation and end of the shift.

---

<div class="post-metadata">

**Author:** ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)\
**Post date:** [March 24, 2020, 7:33pm UTC](https://discuss.elastic.co/t/calculate-the-time-that-passed-between-the-insertion-of-one-record-and-another/221334/2 "2020-03-24T19:33:22Z")

</div>

@yorman_steven_ladino How were you wanting to visualize this difference?

If possible, I would recommend using a single `shift` document with a `start` and `stop` timestamp, so you could first create the document with the `start` timestamp when a shift starts, and then update that document later to add a `stop` timestamp.

```auto
POST shifts/_doc/<shift_id>
{
  "start": "2020-03-23T03:04:15"
}

POST shifts/_update/<shift_id>
{
  "stop": "2020-03-23T09:00:00"
}

```

This is similar to what is described here: [How to calculate the timestamp difference between two actions?](https://discuss.elastic.co/t/how-to-calculate-the-timestamp-difference-between-two-actions/133310/4)

Then you could create a scripted field based on the difference between timestamps. There are some examples of doing date math in painless in [this blog post](https://www.elastic.co/blog/using-painless-kibana-scripted-fields) if you want to learn more.

---

<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:** [April 21, 2020, 7:33pm UTC](https://discuss.elastic.co/t/calculate-the-time-that-passed-between-the-insertion-of-one-record-and-another/221334/3 "2020-04-21T19:33:23Z")

</div>

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