# Kibana date range aggregation by year

**URL:** https://discuss.elastic.co/t/kibana-date-range-aggregation-by-year/34024
**Category:** Kibana
**Created:** [November 6, 2015, 5:16pm UTC](https://discuss.elastic.co/t/kibana-date-range-aggregation-by-year/34024 "2015-11-06T17:16:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Flavio\_Pompermaier](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@Flavio\_Pompermaier](https://discuss.elastic.co/u/Flavio_Pompermaier)
#### Post date: [November 6, 2015, 5:16pm UTC](https://discuss.elastic.co/t/kibana-date-range-aggregation-by-year/34024/1 "2015-11-06T17:16:58Z")

</div>

Hi to all,  
in my use case I have an index with 2 date fields (from and to).  
I'd like to be able to show the sum of all days covered by such interval aggregated by year...For example, if I have 2 docs in the form \<id, from,to\> like the following:

\<1, 2010/01/01,2012/01/30\> and  
\<2, 2011/01/01,2011/01/01\> I would like to show

2010: 365  
2011: 366  
2012: 395

Is it something possible?

Best,  
Flavio

---

<div class="post-metadata">

### Author: ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)
#### Post date: [November 7, 2015, 4:29pm UTC](https://discuss.elastic.co/t/kibana-date-range-aggregation-by-year/34024/2 "2015-11-07T16:29:25Z")

</div>

Two options I can think of: (1) use Groovy in Kibana scripted fields to do date math and derive the year field; (2) index the year as a field and do aggregations based on that.

---

<div class="post-metadata">

### Author: ![Flavio\_Pompermaier](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@Flavio\_Pompermaier](https://discuss.elastic.co/u/Flavio_Pompermaier)
#### Post date: [November 9, 2015, 8:48am UTC](https://discuss.elastic.co/t/kibana-date-range-aggregation-by-year/34024/3 "2015-11-09T08:48:14Z")

</div>

Hi Tanya,  
thanks for the answer. I want to compute also the number of days for each year and aggregate that. Do you think it's possible using a scripted field?

---

<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: [July 6, 2017, 2:09pm UTC](https://discuss.elastic.co/t/kibana-date-range-aggregation-by-year/34024/4 "2017-07-06T14:09:31Z")

</div>


