# Date difference scripted field

**URL:** <https://discuss.elastic.co/t/date-difference-scripted-field/136611>\
**Category:** Kibana\
**Created:** [June 20, 2018, 6:20am UTC](https://discuss.elastic.co/t/date-difference-scripted-field/136611 "2018-06-20T06:20:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishantanu](https://avatars.discourse-cdn.com/v4/letter/i/da6949/32.png) [@ishantanu](https://discuss.elastic.co/u/ishantanu)\
**Post date:** [June 20, 2018, 6:20am UTC](https://discuss.elastic.co/t/date-difference-scripted-field/136611/1 "2018-06-20T06:20:59Z")

</div>

Hi,

I wanted to find the difference between two fields using scripted fields. Here are the two date fields and their format:

```auto
start_time - June 17th 2018, 09:44:46.000
end_time - June 17th 2018, 09:44:49.000

```

Which will give `proc_time`.

Here's what I am trying to do in scripted fields:  
`doc['start_time'].date.millis - doc['end_time'].date.millis` But this is returning the processing time which is deducted from epoch time.

For example, if my processing time is 2 seconds, then the output will be `epoch time - 2 seconds`.  
Which is not what I want.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [June 20, 2018, 6:59pm UTC](https://discuss.elastic.co/t/date-difference-scripted-field/136611/2 "2018-06-20T18:59:30Z")

</div>

What type are you selecting for the scripted field?

---

<div class="post-metadata">

**Author:** ![ishantanu](https://avatars.discourse-cdn.com/v4/letter/i/da6949/32.png) [@ishantanu](https://discuss.elastic.co/u/ishantanu)\
**Post date:** [June 21, 2018, 5:45am UTC](https://discuss.elastic.co/t/date-difference-scripted-field/136611/3 "2018-06-21T05:45:02Z")

</div>

This is solved. I used number and duration to find the difference between two time values in seconds.

---

<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 19, 2018, 5:45am UTC](https://discuss.elastic.co/t/date-difference-scripted-field/136611/4 "2018-07-19T05:45:08Z")

</div>

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