# Visualize based on dates

**URL:** <https://discuss.elastic.co/t/visualize-based-on-dates/358859>\
**Category:** Kibana\
**Tags:** lens\
**Created:** [May 6, 2024, 3:25pm UTC](https://discuss.elastic.co/t/visualize-based-on-dates/358859 "2024-05-06T15:25:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tegerei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tegerei/32/132992_2.png) [@tegerei](https://discuss.elastic.co/u/tegerei)\
**Post date:** [May 6, 2024, 3:25pm UTC](https://discuss.elastic.co/t/visualize-based-on-dates/358859/1 "2024-05-06T15:25:25Z")

</div>

Hello,

I have a field that has the expiry date of an SSL certificate. The field is in form of a Date. I need to create a visualization with color to show when the date is nearing as follows:

- Show Yellow when the date is 30 days or less, but not less than 10

- Red when 10 days or less are remaining.

I would like to use the alert feature when the above conditions are met.

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [May 6, 2024, 7:58pm UTC](https://discuss.elastic.co/t/visualize-based-on-dates/358859/2 "2024-05-06T19:58:13Z")

</div>

Thanks for reaching out here, @tegerei.

You may want to check out our documentation on [creating a dashboard](https://www.elastic.co/guide/en/kibana/current/dashboard.html), as well as this [similar post](https://discuss.elastic.co/t/color-in-a-field-in-the-dashboard/245218). Our [documentation on alerting](https://www.elastic.co/guide/en/kibana/current/alerting-getting-started.html) may also be a good thing to check out.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [May 7, 2024, 8:22am UTC](https://discuss.elastic.co/t/visualize-based-on-dates/358859/3 "2024-05-07T08:22:43Z")

</div>

Hi @tegerei

sure, you can build something like that with a Lens Metric chart, leveraging the power of Lens formula.

Start with a Dashboard, then create a visualization, that will lead you to the Lens editor, and pick the `Metric` chart type.  
Now define a `Primary metric` as follow:

 ![Screenshot 2024-05-07 at 10.09.43](https://us1.discourse-cdn.com/elastic/original/3X/9/c/9ce21aabe0a76e927f580d2820bb5be125e7bb16.png)

(I've used here the `@timestamp` field as "field that contains the expiration date").

Now format it as `Duration` with the control underneath, from `Milliseconds`:

![Screenshot 2024-05-07 at 10.11.38](https://us1.discourse-cdn.com/elastic/original/3X/3/b/3b6a584d2ef9f7623112979a7ee4149b0e26dea0.png)

I've also added a nice postfix "to renew" there, but it's not mandatory.

Next configure a dynamic coloring strategy with 2 colors:

![Screenshot 2024-05-07 at 10.11.52](https://us1.discourse-cdn.com/elastic/original/3X/8/9/8980f8c8b60ac62a0520d7e5a681bd21d2f92fe9.png)

Just mind that values there are milliseconds (so for yellow I've set 10 days in ms: `864000`):

 ![Screenshot 2024-05-07 at 10.11.59](https://us1.discourse-cdn.com/elastic/original/3X/b/6/b6425f2618d2f36c7bd1bd659a0fcaf336943744.png)

If you want green/other color for more than 30 days, just configure a new color with a `2592000` value.

Here's the result so far:

 ![Screenshot 2024-05-07 at 10.12.08](https://us1.discourse-cdn.com/elastic/original/3X/9/0/903a29fae504e414f721eb3b0565715fbace9ea8.png)

Now save and return back to the dashboard. Click the top-right `...` icon of the panel and choose `Settings` to configure a custom time range for the panel:

![Screenshot 2024-05-07 at 10.13.11](https://us1.discourse-cdn.com/elastic/original/3X/8/8/88e57a5a737199f85faf3246bc41d040710e672f.png)

Now the panel will always point to the last day (no matter what time range you pick in the dashboard) and will change the color based on the field value:

 ![Screenshot 2024-05-07 at 10.13.17](https://us1.discourse-cdn.com/elastic/original/3X/c/f/cfbf271f8ffb5a779ebac4574d2bd00843ae7b13.png)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![tegerei](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tegerei/32/132992_2.png) [@tegerei](https://discuss.elastic.co/u/tegerei)\
**Post date:** [May 7, 2024, 3:29pm UTC](https://discuss.elastic.co/t/visualize-based-on-dates/358859/4 "2024-05-07T15:29:18Z")

</div>

Thanks for the reply. However, I could not proceed because I got the following error  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/d/6dddaae8b18aaf356cc74ed0cfcec52f13fec9d8.png)

I am using 7.17.9 stack.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [May 8, 2024, 8:15am UTC](https://discuss.elastic.co/t/visualize-based-on-dates/358859/5 "2024-05-08T08:15:37Z")

</div>

The `now()` function has been introduced in 8.9.0 version.
