# Search a date time field based off another date time field in the same log entry

**URL:** <https://discuss.elastic.co/t/search-a-date-time-field-based-off-another-date-time-field-in-the-same-log-entry/179423>\
**Category:** Kibana\
**Created:** [May 2, 2019, 6:14pm UTC](https://discuss.elastic.co/t/search-a-date-time-field-based-off-another-date-time-field-in-the-same-log-entry/179423 "2019-05-02T18:14:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_the\_geek](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jeff\_the\_geek](https://discuss.elastic.co/u/Jeff_the_geek)\
**Post date:** [May 2, 2019, 6:14pm UTC](https://discuss.elastic.co/t/search-a-date-time-field-based-off-another-date-time-field-in-the-same-log-entry/179423/1 "2019-05-02T18:14:15Z")

</div>

What I'm trying to do is find if a certain timefield is within tolerance of another.

So, for example I want:

> entrytime:[@timestamp-4h TO @timestamp+4h]

...where @timestamp is the the timestamp on this logentry (and is my timestamp index)

I will use this to build a visualization (table) that has a count with buckets being on a status field.

---

<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:** [May 2, 2019, 6:53pm UTC](https://discuss.elastic.co/t/search-a-date-time-field-based-off-another-date-time-field-in-the-same-log-entry/179423/2 "2019-05-02T18:53:37Z")

</div>

You can kind of do this using a scripted field. You can create a scripted field in the index pattern settings. It would be something like this:

```auto
doc['entrytime'].value.millis - doc['@timestamp'].value.millis

```

Let's call this scripted field `date_diff`. This would give you the number of milliseconds between your two dates. Since 4 hours is equivalent to 14400000 milliseconds, you could then do a search like this (assuming you're using [KQL](https://www.elastic.co/guide/en/kibana/current/kuery-query.html), not Lucene, as Lucene doesn't support Kibana's scripted fields):

```auto
date_diff > -14400000 and date_diff < -14400000

```

Alternatively, you could create a filter (via the Add Filter dialog) where `date_diff` is between -14400000 and 14400000.

---

<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:** [May 30, 2019, 6:53pm UTC](https://discuss.elastic.co/t/search-a-date-time-field-based-off-another-date-time-field-in-the-same-log-entry/179423/3 "2019-05-30T18:53:38Z")

</div>

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