# Visualization lens chart filter by max and min timestamp

**URL:** https://discuss.elastic.co/t/visualization-lens-chart-filter-by-max-and-min-timestamp/350922
**Category:** Kibana
**Created:** [January 12, 2024, 8:46am UTC](https://discuss.elastic.co/t/visualization-lens-chart-filter-by-max-and-min-timestamp/350922 "2024-01-12T08:46:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Liam619](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liam619/32/129678_2.png) [@Liam619](https://discuss.elastic.co/u/Liam619)
#### Post date: [January 12, 2024, 8:46am UTC](https://discuss.elastic.co/t/visualization-lens-chart-filter-by-max-and-min-timestamp/350922/1 "2024-01-12T08:46:28Z")

</div>

Hi everyone,

I'm trying to figure out how to filter timestamp by getting the max and min of 2 date. I have tried to use "aggs" but I get error instead.

I have a sql query condition that I need to turn into kibana chart to filter the data from the index document.

Below is the sample sql query that use for the db result. Appreciate if there are some insight on how to do this.

```auto
MIN(BDT.ACTIVATE_DT) START_TIME, 
MAX(BDT.APPROVE_DT) END_TIME,
ROUND(((MAX(BDT.APPROVE_DT) - MIN(BDT.ACTIVATE_DT)) * 24), 2) TIME_TAKEN_HR

```

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [January 19, 2024, 11:13pm UTC](https://discuss.elastic.co/t/visualization-lens-chart-filter-by-max-and-min-timestamp/350922/2 "2024-01-19T23:13:38Z")

</div>

Hi, I'm pretty sure you don't need an SQL query for this. If you are in Lens and need to filter documents based on a time range, you can click the "Add filter" button, which is a "plus" icon, to show a form where you select your time field, select `is between`, and then enter the min and max dates.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/8/28bad2b99c3c87d669ef9e5a9f8d12b24212f8e5.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: [February 16, 2024, 11:14pm UTC](https://discuss.elastic.co/t/visualization-lens-chart-filter-by-max-and-min-timestamp/350922/3 "2024-02-16T23:14:34Z")

</div>

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