# Painless script to get date difference

**URL:** <https://discuss.elastic.co/t/painless-script-to-get-date-difference/223461>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [March 13, 2020, 7:45am UTC](https://discuss.elastic.co/t/painless-script-to-get-date-difference/223461 "2020-03-13T07:45:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 13, 2020, 8:28am UTC](https://discuss.elastic.co/t/painless-script-to-get-date-difference/223461/2 "2020-03-13T08:28:04Z")

</div>

It sounds like at least one of your fields is a `date`, not a number. If a field shows up as date type in your mapping, you have to access the value with `doc['myFieldNameHere'].value.millis` to get the timestamp value as a number.

Also see here [Kibana painless- Difference in dates in days](https://discuss.elastic.co/t/kibana-painless-difference-in-dates-in-days/169201)

---

_[View the full topic](https://discuss.elastic.co/t/painless-script-to-get-date-difference/223461)._
