# Unable to calculate duration by 2 dates fields

**URL:** <https://discuss.elastic.co/t/unable-to-calculate-duration-by-2-dates-fields/194833>\
**Category:** Elasticsearch\
**Created:** [August 12, 2019, 11:11am UTC](https://discuss.elastic.co/t/unable-to-calculate-duration-by-2-dates-fields/194833 "2019-08-12T11:11:20Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 12, 2019, 12:32pm UTC](https://discuss.elastic.co/t/unable-to-calculate-duration-by-2-dates-fields/194833/3 "2019-08-12T12:32:54Z")

</div>

how about this

```auto
DELETE test

PUT test/_doc/1?refresh
{
  "request": {
    "time": "2019-08-04T20:02:15.459Z"
  },
  "response": {
    "time": "2019-08-04T20:04:03.009Z"
  }
}

POST test/_update_by_query
{
    "script" : {
      "lang" : "painless",
    "source": "ctx._source.duration_in_ms = ZonedDateTime.parse(ctx._source.response.time).toInstant().toEpochMilli() - ZonedDateTime.parse(ctx._source.request.time).toInstant().toEpochMilli()"
  }
}

GET test/_doc/1

```

---

_[View the full topic](https://discuss.elastic.co/t/unable-to-calculate-duration-by-2-dates-fields/194833)._
