# Comparing date in same document

**URL:** <https://discuss.elastic.co/t/comparing-date-in-same-document/297221>\
**Category:** Kibana\
**Created:** [February 15, 2022, 9:47am UTC](https://discuss.elastic.co/t/comparing-date-in-same-document/297221 "2022-02-15T09:47:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbviz](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@dbviz](https://discuss.elastic.co/u/dbviz)\
**Post date:** [February 15, 2022, 9:47am UTC](https://discuss.elastic.co/t/comparing-date-in-same-document/297221/1 "2022-02-15T09:47:36Z")

</div>

Hello Elastic Team,

I have two dates fields with format

`2022-02-10T23:00:00.000Z`

I want to compare them , but I don't want to compare the time. Only the date part like :

`2022-02-10`

I tried using Scripted Fields with

```auto

LocalDateTime.ofInstant( Instant.ofEpochMilli(doc['date'].value.millis), ZoneId.of('Europe/Paris') ).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
== 
LocalDateTime.ofInstant( Instant.ofEpochMilli(doc['cutoff'].value.millis), ZoneId.of('Europe/Paris') ).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))

```

But It return True only ...

2nd question, how can I do it using Dev Tools (API) whitout Scripted Fields ?

Any pointers to resolve the issue are really appreciated.

Thank you

---

<div class="post-metadata">

**Author:** ![majagrubic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/majagrubic/32/74459_2.png) [@majagrubic](https://discuss.elastic.co/u/majagrubic)\
**Post date:** [February 16, 2022, 3:30pm UTC](https://discuss.elastic.co/t/comparing-date-in-same-document/297221/2 "2022-02-16T15:30:45Z")

</div>

The value returned from `doc['date'].value` is a string value, the call to `milis` on it makes no sense. I am surprised Painless doesn't throw an exception there.

As to the second part of your question - we have [runtime fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html) on Elasticsearch side, which are not tied to Kibana. This way you can create fields on read time, and access them from the console.

---

<div class="post-metadata">

**Author:** ![dbviz](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@dbviz](https://discuss.elastic.co/u/dbviz)\
**Post date:** [February 21, 2022, 9:46am UTC](https://discuss.elastic.co/t/comparing-date-in-same-document/297221/3 "2022-02-21T09:46:17Z")

</div>

Hello Maja,

Thank you for your help.

I finally used this code to convert/ compare the date and it works pretty well

`ZonedDateTime.from(doc['date'].value).withZoneSameInstant(ZoneId.of('Europe/Paris')).getDayOfYear().equals( ZonedDateTime.from(doc['cutoff'].value).withZoneSameInstant(ZoneId.of('Europe/Paris')).getDayOfYear() )`

I will take a look about runtime fields, thank you 😃

---

<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:** [March 21, 2022, 9:47am UTC](https://discuss.elastic.co/t/comparing-date-in-same-document/297221/4 "2022-03-21T09:47:12Z")

</div>

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