# Filter Kibana dashboard date range by day of week

**URL:** <https://discuss.elastic.co/t/filter-kibana-dashboard-date-range-by-day-of-week/282394>\
**Category:** Kibana\
**Created:** [August 24, 2021, 6:18pm UTC](https://discuss.elastic.co/t/filter-kibana-dashboard-date-range-by-day-of-week/282394 "2021-08-24T18:18:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiago.ferneda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiago.ferneda/32/93652_2.png) [@tiago.ferneda](https://discuss.elastic.co/u/tiago.ferneda)\
**Post date:** [August 24, 2021, 6:18pm UTC](https://discuss.elastic.co/t/filter-kibana-dashboard-date-range-by-day-of-week/282394/1 "2021-08-24T18:18:05Z")

</div>

Hi,  
I'm having some trouble in creating a specific elasticsearch query DSL for a Kibana Dashboard. I need to filter data by created date and time. I apllied the solution bellow so we can bring data to our scope, we call it as "solve today", bringing some data from yesterday and a period from today to this context.

```auto
{
  "query": {
    "range": {
      "data.created": {
        "gte": "now-1d/d+10h",
        "lt": "now/d+10h"
      }
    }
  }
}

```

It works fine from tuesday to friday but we need a diferent rule for the monday, something like the code bellow.

```auto
{
  "query": {
    "range": {
      "data.created": {
        "gte": "now-3d/d+10h",
        "lt": "now/d+10h"
      }
    }
  }
}

```

There is anyway I could do this automatically? I tried some scripts but it doesn't work fine with date ranges.

---

<div class="post-metadata">

**Author:** ![tiago.ferneda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiago.ferneda/32/93652_2.png) [@tiago.ferneda](https://discuss.elastic.co/u/tiago.ferneda)\
**Post date:** [August 26, 2021, 1:37pm UTC](https://discuss.elastic.co/t/filter-kibana-dashboard-date-range-by-day-of-week/282394/2 "2021-08-26T13:37:35Z")

</div>

O created a scripted field bellow and it solved the problem. Now I'm just using it as a filter on Kibana dash where it is true.

```auto
int created_hour = doc['data.created'].value.getHour();
int created_day_of_week = doc['data.created'].value.getDayOfWeek();
ZonedDateTime currentdate = ZonedDateTime.ofInstant(Instant.ofEpochMilli(new Date().getTime()), ZoneId.of('GMT'));

ZonedDateTime solve_limit = doc['data.created'].value.withHour(19).withMinute(0).withSecond(0).withNano(0);

if(created_day_of_week == 6){
    solve_limit = solve_limit.plusDays(2)
}
else if(created_day_of_week == 7){
    solve_limit = solve_limit.plusDays(1)
}
else {
    if(created_hour >= 18){
        if(created_day_of_week == 5) {
            solve_limit = solve_limit.plusDays(3)
        }
        else {
            solve_limit = solve_limit.plusDays(1)
        }
    }
}

long solve_limit_millis = solve_limit.truncatedTo(ChronoUnit.DAYS).toInstant().toEpochMilli();
long currentdate_millis = currentdate.truncatedTo(ChronoUnit.DAYS).toInstant().toEpochMilli();

long diff = solve_limit_millis - currentdate_millis;

diff == 0

```

---

<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:** [September 23, 2021, 1:38pm UTC](https://discuss.elastic.co/t/filter-kibana-dashboard-date-range-by-day-of-week/282394/3 "2021-09-23T13:38:27Z")

</div>

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