# How to calculate the timestamp difference between two actions?

**URL:** <https://discuss.elastic.co/t/how-to-calculate-the-timestamp-difference-between-two-actions/133310>\
**Category:** Kibana\
**Created:** [May 25, 2018, 11:21am UTC](https://discuss.elastic.co/t/how-to-calculate-the-timestamp-difference-between-two-actions/133310 "2018-05-25T11:21:29Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jen-huang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jen-huang/32/74327_2.png) [@jen-huang](https://discuss.elastic.co/u/jen-huang)\
**Post date:** [June 8, 2018, 5:47pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-timestamp-difference-between-two-actions/133310/4 "2018-06-08T17:47:16Z")

</div>

I recommend restructuring the data sent to Elasticsearch so that each document looks something like this:

```auto
{
  "session_id": 123456,
  "login_time": "May 20th 2018, 15:41:32.111",
  "logout_time": "May 21th 2018, 10:39:01.761",
}

```

Then, you can add a [Scripted field in Kibana](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html) to calculate the difference between `login_time` and `logout_time`.

You can read more about [modeling data for Elasticsearch here](https://www.elastic.co/guide/en/elasticsearch/guide/current/modeling-your-data.html).

---

_[View the full topic](https://discuss.elastic.co/t/how-to-calculate-the-timestamp-difference-between-two-actions/133310)._
