# Extract Day, Month and year from Today using painless script

**URL:** https://discuss.elastic.co/t/extract-day-month-and-year-from-today-using-painless-script/280431
**Category:** Kibana
**Tags:** painless
**Created:** [August 4, 2021, 12:48pm UTC](https://discuss.elastic.co/t/extract-day-month-and-year-from-today-using-painless-script/280431 "2021-08-04T12:48:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hiteshmakky](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hiteshmakky](https://discuss.elastic.co/u/hiteshmakky)
#### Post date: [August 4, 2021, 12:48pm UTC](https://discuss.elastic.co/t/extract-day-month-and-year-from-today-using-painless-script/280431/1 "2021-08-04T12:48:12Z")

</div>

Hi Friends,  
I am new to the EKL stack. I am trying to calculate MTD sales from data set.  
We have three columns

1. Product Code
2. Date (dd-MM-yyyy format)
3. Sales  
All I am trying to do is calculate MTD sales for e.g. If today is 04th of Aug 2021. The code should be able to filter the records from 01st Aug 2021 to 04th Aug 2021 and sum the Sales column. The date which do not fall into the filter condition of MTD should not be considered for the MTD calculation.

|Product\_Code|Date|Sales|  
|P1|02-08-2021|55000|  
|P1|03-08-2021|55000|  
|P2|01-08-2021|15842|  
|P3|04-08-2021|14892|  
|P4|20-10-2020|59000|  
|P4|30-10-2020|59000|  
|P5|21-04-2021|45000|  
|P6|10-06-2021|0|  
|P7|08-02-2021|86771|  
|P8|22-01-2021|7295|  
|P8|21-01-2022|7295|  
|P9|22-06-2021|47362|  
|P9|24-06-2022|47362|

---

<div class="post-metadata">

### Author: ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)
#### Post date: [August 5, 2021, 2:50am UTC](https://discuss.elastic.co/t/extract-day-month-and-year-from-today-using-painless-script/280431/2 "2021-08-05T02:50:15Z")

</div>

Hello,

Two questions for you. What is MTD sales?  
Which chart types did you try? If you look at lens and data table?

For example - here I am looking at logs and bytes. I made a data table for timestamp and bytes sum in lens. And I can look at different time period by using the time picker on top.

 ![Screen Shot 2021-08-04 at 10.48.48 PM](https://us1.discourse-cdn.com/elastic/original/3X/5/7/57acc25ac4100a91419c1b5a89a4c5b2c00ed4fa.jpeg)

> **[Kibana Lens](https://www.elastic.co/kibana/kibana-lens)**
>
> Bring instant clarity to your data with the Kibana Lens UI. Drag and drop Elasticsearch field types for easy data visualization — no prior Kibana experience required.

Does that help?

Thanks  
Bhavya

---

<div class="post-metadata">

### Author: ![hiteshmakky](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hiteshmakky](https://discuss.elastic.co/u/hiteshmakky)
#### Post date: [August 5, 2021, 2:45pm UTC](https://discuss.elastic.co/t/extract-day-month-and-year-from-today-using-painless-script/280431/3 "2021-08-05T14:45:32Z")

</div>

Hi Bhavya,

MTD stand for Month to Date. This is a common mertic used for performance monitoring dashboard.

For e.g. If today is 28th July 2021, then the MTD sales metric should give sales from 01st of July 2021 till 28th of July 2021  
If today is 15th Aug 2021, then the MTD sales metric should give sales from 01st of Aug 2021 till 15th of Aug 2021.

MTD metric always starts from 01st day of a month of today till today.

Let write a sudo code for reference:  
Today (system date ) = 28th Jul 2021  
MTD Sales = Sum (All the sales that has occured between 01st of July 2021 till 28th July 2021 inclusing both the start date and end)

Also a pointer, I want to derive the MTD calucation using painless script

Hope this gives better clairfication

---

<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 2, 2021, 2:46pm UTC](https://discuss.elastic.co/t/extract-day-month-and-year-from-today-using-painless-script/280431/4 "2021-09-02T14:46:18Z")

</div>

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