# Date fields comparison

**URL:** https://discuss.elastic.co/t/date-fields-comparison/272724
**Category:** Kibana
**Created:** [May 11, 2021, 4:14pm UTC](https://discuss.elastic.co/t/date-fields-comparison/272724 "2021-05-11T16:14:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![g\_k\_b](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@g\_k\_b](https://discuss.elastic.co/u/g_k_b)
#### Post date: [May 11, 2021, 4:14pm UTC](https://discuss.elastic.co/t/date-fields-comparison/272724/1 "2021-05-11T16:14:24Z")

</div>

Hi There!  
I would desire to create a scripted field comparing 2 date fields in Kibana, in particular:  
I want to use current date ( new Date().getTime() ) and a date field I indexed already (named _expiring date_). The comparison I want to do is something like :"if _current date_ is more recent than _expiring date_ return _working_, if not return _expired_.

This syntax:  
_new Date().getTime() \> doc['expiting date'].value_  
doesn't work.

Could anyone help me please? Thanks in advance!

---

<div class="post-metadata">

### Author: ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)
#### Post date: [May 11, 2021, 11:04pm UTC](https://discuss.elastic.co/t/date-fields-comparison/272724/2 "2021-05-11T23:04:27Z")

</div>

There are dozens of examples out there.  
Here are a couple of them --\>

> [@Calculate Difference between 2 Dates in Scipted Field](https://discuss.elastic.co/t/calculate-difference-between-2-dates-in-scipted-field/153129):
>
> Hi All, I am trying to create a new scripted field by calculating the difference(in seconds) between 2 date in the following format ` October 15th 2018, 22:15:27.823 The two fields I am using are start\_time and end\_time. I have tried various method covering both Painless and expression as language. Every time I try I get different error. Example:- if(!doc['end\_time'].empty) { return doc['end\_time'].value - doc['start\_time'].value } Error it gave is:- "caused\_by":{"type":"parse\_except…

> <https://stackoverflow.com/questions/31673468/kibana-time-delta-between-two-fields>

> [@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

---

<div class="post-metadata">

### Author: ![g\_k\_b](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@g\_k\_b](https://discuss.elastic.co/u/g_k_b)
#### Post date: [May 12, 2021, 12:32pm UTC](https://discuss.elastic.co/t/date-fields-comparison/272724/3 "2021-05-12T12:32:58Z")

</div>

Thank you, I read already something similar to that since, as you say, there are dozens of similar topics. The very aim of my request is to create a kind of gantt diagram in Kibana, or something similar to it. I was wondering to create a proper date field as an escamotage to reach my point, but if you guys have a "more direct" suggestion for me, tell me 🙂

---

<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: [June 9, 2021, 12:33pm UTC](https://discuss.elastic.co/t/date-fields-comparison/272724/4 "2021-06-09T12:33:48Z")

</div>

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