# Date Column difference in days using Scripted fields

**URL:** https://discuss.elastic.co/t/date-column-difference-in-days-using-scripted-fields/178255
**Category:** Kibana
**Created:** [April 24, 2019, 12:54pm UTC](https://discuss.elastic.co/t/date-column-difference-in-days-using-scripted-fields/178255 "2019-04-24T12:54:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ram18](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@Ram18](https://discuss.elastic.co/u/Ram18)
#### Post date: [April 24, 2019, 12:54pm UTC](https://discuss.elastic.co/t/date-column-difference-in-days-using-scripted-fields/178255/1 "2019-04-24T12:54:15Z")

</div>

Hi,  
I am trying to get the difference between 2 date columns in days. I have used painless language and created a scripted field column. The issue here is, the difference in days between the end of the year and start of the next year creates problem and getting wrong values. please let me know, how to handle this and get the exact difference in days.

> doc['received\_dt'].date.dayOfYear- doc['start\_dt'].date.dayOfYear

---

<div class="post-metadata">

### Author: ![LizaD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lizad/32/51074_2.png) [@LizaD](https://discuss.elastic.co/u/LizaD)
#### Post date: [April 24, 2019, 7:57pm UTC](https://discuss.elastic.co/t/date-column-difference-in-days-using-scripted-fields/178255/2 "2019-04-24T19:57:44Z")

</div>

Hi! I found this discuss post that might be similar to what you are asking:

> [@Kibana painless- Difference in dates in days](https://discuss.elastic.co/t/kibana-painless-difference-in-dates-in-days/169201):
>
> I have two date fields - Date1 and Date2, both are in date format I want to calculate days between the two dates. I tried doc['date2'].value - doc['date1'].value, this is not giving the expected return value

There is also this blog post: [Using Painless in Kibana scripted fields | Elastic Blog](https://www.elastic.co/blog/using-painless-kibana-scripted-fields)

Can you check it out and see if it helps?

---

<div class="post-metadata">

### Author: ![Ram18](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@Ram18](https://discuss.elastic.co/u/Ram18)
#### Post date: [April 26, 2019, 6:00am UTC](https://discuss.elastic.co/t/date-column-difference-in-days-using-scripted-fields/178255/3 "2019-04-26T06:00:06Z")

</div>

Liza, Yes the discussion post helped me to narrow down the things. Thanks!

---

<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: [May 24, 2019, 6:00am UTC](https://discuss.elastic.co/t/date-column-difference-in-days-using-scripted-fields/178255/4 "2019-05-24T06:00:08Z")

</div>

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