# How to calculate Date difference using scripted fields

**URL:** https://discuss.elastic.co/t/how-to-calculate-date-difference-using-scripted-fields/170763
**Category:** Logstash
**Created:** [March 4, 2019, 4:23pm UTC](https://discuss.elastic.co/t/how-to-calculate-date-difference-using-scripted-fields/170763 "2019-03-04T16:23:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![adityaPsl](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@adityaPsl](https://discuss.elastic.co/u/adityaPsl)
#### Post date: [March 4, 2019, 4:23pm UTC](https://discuss.elastic.co/t/how-to-calculate-date-difference-using-scripted-fields/170763/1 "2019-03-04T16:23:01Z")

</div>

Hello Team,

I have a use case to take the difference between two dates in the form of year,month,day,hour,minute,second format.

for example

10-mar-2019 10:00:00 - 09-mar-2019 10:00:00 would be = 0 years,0 month,1 day, 0 Hrs,0 Mins,0 Sec.

I was able to find the diff using scripted field (painless script)

doc['date1'].date.toMillis() - doc['date2'].date.toMillis()

is there any way to convert miliseconds to above format.

Thank you for your help and support.

Thank You,  
Aditya

---

<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: [April 1, 2019, 4:27pm UTC](https://discuss.elastic.co/t/how-to-calculate-date-difference-using-scripted-fields/170763/2 "2019-04-01T16:27:32Z")

</div>

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