# Showcasing Date as yesterday, this week, this month in Kibana Dashboard control options

**URL:** <https://discuss.elastic.co/t/showcasing-date-as-yesterday-this-week-this-month-in-kibana-dashboard-control-options/345435>\
**Category:** Kibana\
**Tags:** dashboard, visualisation\
**Created:** [October 20, 2023, 5:58am UTC](https://discuss.elastic.co/t/showcasing-date-as-yesterday-this-week-this-month-in-kibana-dashboard-control-options/345435 "2023-10-20T05:58:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathur7vidit](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mathur7vidit](https://discuss.elastic.co/u/mathur7vidit)\
**Post date:** [October 20, 2023, 5:58am UTC](https://discuss.elastic.co/t/showcasing-date-as-yesterday-this-week-this-month-in-kibana-dashboard-control-options/345435/1 "2023-10-20T05:58:40Z")

</div>

Hi Team,  
i have a date field which showcases date only as per below snap.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/a/2ac47baadbdae8d18449e915c2eddd4b58ba43da.png)  
this date is basically being extracted from one of the available field invoice\_date. Now my requirement is that suppose today is 20 Oct and i have data for 19th october, then 19th date should appear as yesterday.  
Also, another way which i was thinking is to replicate invoice\_date field and use relative time, will it help?

---

<div class="post-metadata">

**Author:** ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)\
**Post date:** [October 26, 2023, 4:39pm UTC](https://discuss.elastic.co/t/showcasing-date-as-yesterday-this-week-this-month-in-kibana-dashboard-control-options/345435/2 "2023-10-26T16:39:53Z")

</div>

The easiest way is to use the _Relative Date_ format in the Data view for your date field

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/c/fcb4818e72ddd8e8d4cb50580ff6891dbf9e42a2.png)

But if you want full control of the texts you can create a new runtime field that computes the date distance and then start coding your checks.

For this dataset with just a `date` field:

```auto
PUT discuss-345435
{
  "mappings": {
    "properties": {
      "date": { "type": "date"}
    }
  }
}

POST discuss-345435/_bulk
{ "index": {}}
{ "date": "2023-10-20"}
{ "index": {}}
{ "date": "2023-10-21"}
{ "index": {}}
{ "date": "2023-10-22"}
{ "index": {}}
{ "date": "2023-10-23"}
{ "index": {}}
{ "date": "2023-10-24"}
{ "index": {}}
{ "date": "2023-10-25"}
{ "index": {}}
{ "date": "2023-10-26"}
{ "index": {}}
{ "date": "2023-10-27"}
{ "index": {}}
{ "date": "2023-10-28"}

```

I'll show only for `Yesterday` (the easy one) and leave the rest for you:

```auto
Instant Currentdate = Instant.ofEpochMilli(new Date().getTime());
Instant Startdate = Instant.ofEpochMilli(doc['date'].value.getMillis());
long days_ago = ChronoUnit.DAYS.between(Startdate, Currentdate);

if (days_ago == 1){
  emit('Yesterday');
} else {
  DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  emit(doc['date'].value.format(dtf));
}

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/c/7c7e3f36ffa9b8321e2811ed23feb6dad3e9bfa7.png)

And that new field shows like this in Discover

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/1/a13049767a0995142624d6aab4aeaa7a5fef54b1.png)

This is a great resource to work with dates in Painless language

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

---

<div class="post-metadata">

**Author:** ![mathur7vidit](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mathur7vidit](https://discuss.elastic.co/u/mathur7vidit)\
**Post date:** [November 9, 2023, 3:39pm UTC](https://discuss.elastic.co/t/showcasing-date-as-yesterday-this-week-this-month-in-kibana-dashboard-control-options/345435/3 "2023-11-09T15:39:56Z")

</div>

Hi Jsanz. thanks for your reply. this helps 🙂

---

<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:** [December 7, 2023, 3:40pm UTC](https://discuss.elastic.co/t/showcasing-date-as-yesterday-this-week-this-month-in-kibana-dashboard-control-options/345435/4 "2023-12-07T15:40:06Z")

</div>

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