# Diff between two date fields in kibana

**URL:** https://discuss.elastic.co/t/diff-between-two-date-fields-in-kibana/130952
**Category:** Kibana
**Created:** [May 8, 2018, 7:55am UTC](https://discuss.elastic.co/t/diff-between-two-date-fields-in-kibana/130952 "2018-05-08T07:55:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![1862347ba9566e72a47d](https://avatars.discourse-cdn.com/v4/letter/1/cdc98d/32.png) [@1862347ba9566e72a47d](https://discuss.elastic.co/u/1862347ba9566e72a47d)
#### Post date: [May 8, 2018, 7:55am UTC](https://discuss.elastic.co/t/diff-between-two-date-fields-in-kibana/130952/1 "2018-05-08T07:55:31Z")

</div>

A document with several date fields.  
How can I determine the delta of time in days, for example, between several dates in this document?  
Dates can be different years, i.e. It is necessary to minus the older date.  
For example, use `doc['date1'].date.dayOfYear - doc['date0'].date.dayOfYear` a negative number is obtained. Because these dates are from different years. How to get the difference?

---

<div class="post-metadata">

### Author: ![Stacey\_Gammon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stacey_gammon/32/14025_2.png) [@Stacey\_Gammon](https://discuss.elastic.co/u/Stacey_Gammon)
#### Post date: [May 8, 2018, 1:13pm UTC](https://discuss.elastic.co/t/diff-between-two-date-fields-in-kibana/130952/2 "2018-05-08T13:13:45Z")

</div>

Try calculating the difference using `doc[date1].date.millis` or `doc[date1].value` and then converting the number into the value you want (e.g. days).

This stack overflow gives some more details that I think will help you: [https://stackoverflow.com/questions/32658639/how-to-calculate-difference-between-two-datetime-in-elasticsearch](https://stackoverflow.com/questions/32658639/how-to-calculate-difference-between-two-datetime-in-elasticsearch)

---

<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: [June 5, 2018, 1:20pm UTC](https://discuss.elastic.co/t/diff-between-two-date-fields-in-kibana/130952/3 "2018-06-05T13:20:43Z")

</div>

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