# Is there a way to filter by date and not by date time in Kibana Lens?

**URL:** https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387
**Category:** Kibana
**Created:** [November 17, 2021, 4:30am UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387 "2021-11-17T04:30:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Arrick](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Arrick](https://discuss.elastic.co/u/Arrick)
#### Post date: [November 17, 2021, 4:30am UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/1 "2021-11-17T04:30:04Z")

</div>

I've recently tried to use kibana lens and realised that my time filter in control is filtering by date time. Is there a way to make it filter by date instead?  
 ![filter by datetime](https://us1.discourse-cdn.com/elastic/original/3X/2/6/26bddd1758cc3935c422b31d0e991a7b0948203b.png)  
what I plan to obtain is something similar to this:  
 ![expecting datetime](https://us1.discourse-cdn.com/elastic/original/3X/0/6/06bf14d304898608b739d134406a254da3fa6759.png)

---

<div class="post-metadata">

### Author: ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)
#### Post date: [November 22, 2021, 1:05pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/2 "2021-11-22T13:05:57Z")

</div>

One option to do this would be to ingest the current date without time in a separate keyword field, then build the filter based on that. I guess it would be possible to work with date ranges as well, but it won't be as comfortable because AFAIK the UI won't help you with this

---

<div class="post-metadata">

### Author: ![Arrick](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Arrick](https://discuss.elastic.co/u/Arrick)
#### Post date: [November 30, 2021, 8:07am UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/3 "2021-11-30T08:07:09Z")

</div>

From what I know from my research is that I am able to change my date formate by creating a new index pattern data field. However, I am rather confuse on how to move forward. I've read about painless scripting language specifically about datetime formatting too

> [Using Datetime in Painless | Painless Scripting Language [master] | Elastic](https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-datetime.html)

Image below is for creating a new index pattern data field called newDate.

 ![datetime](https://us1.discourse-cdn.com/elastic/original/3X/1/b/1b51a88eb4b02dc22151642af40740f69b392430.png)  
Any advice would be appreciated!

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [November 30, 2021, 3:45pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/4 "2021-11-30T15:45:22Z")

</div>

Hi @Arrick Welcome to the community.

Did you look at setting a custom time interval in Lens Data Table.

 ![Screen Shot 2021-11-30 at 7.43.27 AM](https://us1.discourse-cdn.com/elastic/original/3X/6/4/647681d38d2a33ec5281fb52893e69ac4f58d48c.jpeg)

---

<div class="post-metadata">

### Author: ![Arrick](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Arrick](https://discuss.elastic.co/u/Arrick)
#### Post date: [December 1, 2021, 5:03am UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/5 "2021-12-01T05:03:42Z")

</div>

Hello @stephenb , yep I did look at the settings and it does work

 ![datetime](https://us1.discourse-cdn.com/elastic/original/3X/c/3/c384429ffeabe4bd16bfc8f0b8ef100ae95ba263.png)  
However, my issue is more in the control section and not in the lens section. Where I am unable to change my datetime filter into just date (eg, YYYY/MM/DD).  
 ![datetime](https://us1.discourse-cdn.com/elastic/original/3X/4/8/48f53c581623b79a6580efcaf87df572a083b2bf.png)

---

<div class="post-metadata">

### Author: ![ghudgins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ghudgins/32/138532_2.png) [@ghudgins](https://discuss.elastic.co/u/ghudgins)
#### Post date: [December 3, 2021, 9:57pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/6 "2021-12-03T21:57:51Z")

</div>

This runtime field -

```auto
ZonedDateTime input = doc['@timestamp'].value;
String output = input.format(DateTimeFormatter.ISO_LOCAL_DATE);

emit(output);

```

Will return date in `yyyy-mm-dd`

This page is very useful for date formatters -  
[https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)

---

<div class="post-metadata">

### Author: ![Arrick](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Arrick](https://discuss.elastic.co/u/Arrick)
#### Post date: [December 5, 2021, 3:52am UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/7 "2021-12-05T03:52:31Z")

</div>

Hello @ghudgins , thank you for your help! The documentation is really helpful in understanding. I tried to emit my output but kibana just keeps giving me syntax error when emitting. I noticed that I cant emit anything.  
I tried changing my type from Date to Long but I still gets the same error when emitting.  
 ![emit](https://us1.discourse-cdn.com/elastic/original/3X/9/9/998227706f9da1fec13298431a703ddde73ab995.png)

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [December 5, 2021, 6:32am UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/8 "2021-12-05T06:32:02Z")

</div>

The Field Type should be `keyword` since your are emitting a string that you want to aggregate / filter on.

The code above should work.

 ![Screen Shot 2021-12-04 at 10.31.00 PM](https://us1.discourse-cdn.com/elastic/original/3X/4/5/452da5b5999ea1445f05e8e10ae119324dd7b5b0.png)

.

---

<div class="post-metadata">

### Author: ![Arrick](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Arrick](https://discuss.elastic.co/u/Arrick)
#### Post date: [December 5, 2021, 7:08am UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/9 "2021-12-05T07:08:03Z")

</div>

Thank you @stephenb !! It works perfectly now, thank you so much for your guidance  
 ![newdate](https://us1.discourse-cdn.com/elastic/original/3X/f/e/fedc49e4b9dd760b715236f41c21dac81e78a6bd.png)

---

<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: [January 2, 2022, 7:08am UTC](https://discuss.elastic.co/t/is-there-a-way-to-filter-by-date-and-not-by-date-time-in-kibana-lens/289387/10 "2022-01-02T07:08:08Z")

</div>

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