# Visualization with Date different between 2 fields

**URL:** <https://discuss.elastic.co/t/visualization-with-date-different-between-2-fields/143701>\
**Category:** Kibana\
**Created:** [August 9, 2018, 1:08pm UTC](https://discuss.elastic.co/t/visualization-with-date-different-between-2-fields/143701 "2018-08-09T13:08:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ginu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ginu/32/86297_2.png) [@ginu](https://discuss.elastic.co/u/ginu)\
**Post date:** [August 9, 2018, 1:08pm UTC](https://discuss.elastic.co/t/visualization-with-date-different-between-2-fields/143701/1 "2018-08-09T13:08:32Z")

</div>

Hi there  
I have 2 Date fields **Field1** and **Field2** and **LABEL**. I need to have a visualization which is a list which shows the difference in seconds for all the items:

| **Items| timeTakeninSeconds** |  
|LABEL1| (Field2-Field1).seconds|  
|LABEL2| (Field2-Field1).seconds|  
|LABEL3| (Field2-Field1).seconds|  
....  
....

I tried with scripted field but come with error:  
Discover: class\_cast\_exception: Cannot apply [-] operation to types [org.joda.time.MutableDateTime] and [org.joda.time.MutableDateTime].

Can you please help me with this.

Regards,  
Ginu

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [August 9, 2018, 1:33pm UTC](https://discuss.elastic.co/t/visualization-with-date-different-between-2-fields/143701/2 "2018-08-09T13:33:33Z")

</div>

Can you provide a copy of the script that you tried?

What version of kibana are you using?

Try adding [getMillis](http://www.joda.org/joda-time/apidocs/org/joda/time/base/BaseDateTime.html#getMillis--) to convert `MutableDateTime` to milliseconds

---

<div class="post-metadata">

**Author:** ![ginu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ginu/32/86297_2.png) [@ginu](https://discuss.elastic.co/u/ginu)\
**Post date:** [August 9, 2018, 1:36pm UTC](https://discuss.elastic.co/t/visualization-with-date-different-between-2-fields/143701/3 "2018-08-09T13:36:08Z")

</div>

Hi  
I am using Version: 6.3.1  
my Script :  
doc['LastHeartbeatCheck'].value - doc['currentTimesStamp'].value

`type: number`  
`Format: Duration`  
`InputFormat: seconds`  
`OutputFormat: Human Readable`

the 2 fields (LastHeartbeatCheck, currentTimesStamp) are date fields... with value for eg  
LastHeartbeatCheck = August 9th 2018, 15:00:12.000  
currentTimesStamp=August 9th 2018, 15:00:12.000

---

<div class="post-metadata">

**Author:** ![ginu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ginu/32/86297_2.png) [@ginu](https://discuss.elastic.co/u/ginu)\
**Post date:** [August 9, 2018, 1:52pm UTC](https://discuss.elastic.co/t/visualization-with-date-different-between-2-fields/143701/4 "2018-08-09T13:52:27Z")

</div>

Thanks Nathan for the idea of using .getMillis()

I update dthe script as follows and it worked:  
`doc['LastHeartbeatCheck'].value.getMillis() - doc['LastHeartbeatCheck'].value.getMillis()`

> [@ginu](#):
>
> y Script :  
> doc['LastHeartbeatCheck'].value - doc['currentTimesStamp'].value

---

<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:** [September 6, 2018, 1:52pm UTC](https://discuss.elastic.co/t/visualization-with-date-different-between-2-fields/143701/5 "2018-09-06T13:52:27Z")

</div>

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