# Can I get the datepicker parameters to use in a KQL query in Kibana

**URL:** <https://discuss.elastic.co/t/can-i-get-the-datepicker-parameters-to-use-in-a-kql-query-in-kibana/276756>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [June 23, 2021, 9:13am UTC](https://discuss.elastic.co/t/can-i-get-the-datepicker-parameters-to-use-in-a-kql-query-in-kibana/276756 "2021-06-23T09:13:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tumbledwyer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tumbledwyer/32/89032_2.png) [@tumbledwyer](https://discuss.elastic.co/u/tumbledwyer)\
**Post date:** [June 23, 2021, 9:13am UTC](https://discuss.elastic.co/t/can-i-get-the-datepicker-parameters-to-use-in-a-kql-query-in-kibana/276756/1 "2021-06-23T09:13:08Z")

</div>

My data has multiple date fields so I would like to get the start and end dates from the datepicker to use in a KQL query to further filter my data in a Kibana visualisation.

So let's say I have a document like this:

```auto
{
  admissionDate: "date",
  dischargeDate: "date",
  ...
}

```

My index pattern uses admissionDate as the time field, so the datepicker will filter all patients admitted between the start and end date. But I want to filter patients who have also been discharged before the end date.

I can do this in Vega using the timefilter like this

```auto
%timefilter%: max

```

Is there a way to do this in KQL, something like this?

```auto
dischargeDate < "%timefilter%: max"

```

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [June 23, 2021, 3:00pm UTC](https://discuss.elastic.co/t/can-i-get-the-datepicker-parameters-to-use-in-a-kql-query-in-kibana/276756/2 "2021-06-23T15:00:08Z")

</div>

No, this is not currently supported. You can use regular datemath in KQL, so for example you can do `date > now-7d/d` to find all documents within the last 7 days rounded to midnight.

Here is the issue: [[data.search.aggs] Date range aggregation should support time ranges relative to timepicker · Issue #76433 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/76433#issuecomment-828490030)

---

<div class="post-metadata">

**Author:** ![tumbledwyer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tumbledwyer/32/89032_2.png) [@tumbledwyer](https://discuss.elastic.co/u/tumbledwyer)\
**Post date:** [June 24, 2021, 1:01pm UTC](https://discuss.elastic.co/t/can-i-get-the-datepicker-parameters-to-use-in-a-kql-query-in-kibana/276756/3 "2021-06-24T13:01:26Z")

</div>

Thanks for the reply, I'll keep an eye on the github issue.

I went another way of getting around part of the problem in case anyone is interested.

I created aliases for my index, eg:

```auto
"aliases": {
  "my-index-by-admission": {},
  "my-index-by-discharge": {}
}

```

Then I created an index pattern for each alias, and each one has a different time field. So I can use the same index and filter by a different time field by selecting a different index pattern.

It doesn't get around the problem of using the same datepicker for 2 dates, but it solves some other problems.

If anyone has any better ideas, feel free to drop them here.

---

<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:** [July 22, 2021, 1:02pm UTC](https://discuss.elastic.co/t/can-i-get-the-datepicker-parameters-to-use-in-a-kql-query-in-kibana/276756/4 "2021-07-22T13:02:01Z")

</div>

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