# Comparing 2 dates that are in different fields

**URL:** <https://discuss.elastic.co/t/comparing-2-dates-that-are-in-different-fields/52379>\
**Category:** Kibana\
**Created:** [June 9, 2016, 9:18pm UTC](https://discuss.elastic.co/t/comparing-2-dates-that-are-in-different-fields/52379 "2016-06-09T21:18:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Storm91](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@Storm91](https://discuss.elastic.co/u/Storm91)\
**Post date:** [June 9, 2016, 9:18pm UTC](https://discuss.elastic.co/t/comparing-2-dates-that-are-in-different-fields/52379/1 "2016-06-09T21:18:05Z")

</div>

Hello everyone,

I have a file with several fields.  
I have a field " date.start" and a field "date.end" which contains dates under this format in the json = " 2016-07-01T00:00:00-06:00"

I am trying to create a visualization table to display when date.end \< date.start.

When using the filter " date.end \< date.start" or "date.end LT date.start" I am getting wrong results.

I saw another topic talking about something similar, the solution proposed was :  
`{"constant_score":{"filter": {"script": {"script": "doc['REPORTED_ON'].value > doc['DUE_DATE'].value"}}}}` but I am not sure to understand how to use it in my case.

I am pretty new to this tool and still learning, any help will be appreciated.

Thanks

- Rayan

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [June 10, 2016, 12:10am UTC](https://discuss.elastic.co/t/comparing-2-dates-that-are-in-different-fields/52379/2 "2016-06-10T00:10:32Z")

</div>

You can create the script you mentioned within Kibana. Under Settings \> Indices, select your index and choose the "Scripts" tab. Add a new script and use `doc['date.start'].value > doc['date.end'].value"`. You can then use the new boolean field to select the data.

Though, your filter should work. What is are the types of those fields? You can use the ES API to view the mapping, for Example: `http://localhost:9200/topbeat-*?pretty=true`

---

<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:** [July 6, 2017, 1:50pm UTC](https://discuss.elastic.co/t/comparing-2-dates-that-are-in-different-fields/52379/3 "2017-07-06T13:50:52Z")

</div>


