# Number of Days between date Range

**URL:** <https://discuss.elastic.co/t/number-of-days-between-date-range/78444>\
**Category:** Kibana\
**Created:** [March 14, 2017, 5:18am UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444 "2017-03-14T05:18:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Varun\_Patel](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@Varun\_Patel](https://discuss.elastic.co/u/Varun_Patel)\
**Post date:** [March 14, 2017, 5:18am UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444/1 "2017-03-14T05:18:20Z")

</div>

Hi,

I have a date Range. Lets say 2015-01-01 to 2017-03-01.

I wanted to calculate only days between this two dates using scripted field.

How can i achieve this ?

---

<div class="post-metadata">

**Author:** ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)\
**Post date:** [March 14, 2017, 12:46pm UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444/2 "2017-03-14T12:46:45Z")

</div>

Hi, lets say you have two fields in each of your documents, `start` and `end` that correspond to the `2015-01-01` and `2017-03-01` dates in your example, respectively.

Then you can create a new scripted field with this script (language = Painless):

```
(doc['end'].value.getMillis() - doc['start'].value.getMillis()) / 1000 / 60 / 60 / 24
```

---

<div class="post-metadata">

**Author:** ![Varun\_Patel](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@Varun\_Patel](https://discuss.elastic.co/u/Varun_Patel)\
**Post date:** [March 16, 2017, 4:31am UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444/3 "2017-03-16T04:31:36Z")

</div>

Thanks @shaunak.

---

<div class="post-metadata">

**Author:** ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)\
**Post date:** [March 17, 2017, 4:43pm UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444/4 "2017-03-17T16:43:36Z")

</div>



---

<div class="post-metadata">

**Author:** ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)\
**Post date:** [March 17, 2017, 4:43pm UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444/5 "2017-03-17T16:43:56Z")

</div>



---

<div class="post-metadata">

**Author:** ![lisafitzsimons](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@lisafitzsimons](https://discuss.elastic.co/u/lisafitzsimons)\
**Post date:** [April 6, 2017, 5:04pm UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444/6 "2017-04-06T17:04:02Z")

</div>

I tried this but got the following run time error. I am a real newbie to this, but what could be wrong?

reason":"runtime error","caused\_by":{"type":"illegal\_argument\_exception","reason":"Unable to find dynamic method [getMillis] with [0] arguments for class [java.lang.Long]."},"script\_stack":["return (doc['Completeness Review Date Time Submitted'].value.getMillis() - doc['Completeness Review Date Time Submitted'].value.getMillis()) / 1000 / 60 / 60 / 24

---

<div class="post-metadata">

**Author:** ![Varun\_Patel](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@Varun\_Patel](https://discuss.elastic.co/u/Varun_Patel)\
**Post date:** [April 7, 2017, 5:16am UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444/7 "2017-04-07T05:16:15Z")

</div>

@lisafitzsimons I think this is because syntax what you have written is not correct.

You can just put (doc['Completeness Review Date Time Submitted']) in scripted field and see whether you are getting value or not.

Or you can try this

doc['Completeness Review Date Time Submitted].value/(24_60_60_1000) - doc['Completeness Review Date Time Submitted'].value/(24_60_60_1000)

---

<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:32pm UTC](https://discuss.elastic.co/t/number-of-days-between-date-range/78444/8 "2017-07-06T13:32:23Z")

</div>


