# 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:** 1\
**Showing post:** 2

<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.

---

_[View the full topic](https://discuss.elastic.co/t/calculate-the-time-that-passed-between-the-insertion-of-one-record-and-another/221334)._
