# To get end date of week in date histogram

**URL:** <https://discuss.elastic.co/t/to-get-end-date-of-week-in-date-histogram/116591>\
**Category:** Elasticsearch\
**Created:** [January 23, 2018, 5:04am UTC](https://discuss.elastic.co/t/to-get-end-date-of-week-in-date-histogram/116591 "2018-01-23T05:04:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgopi2win](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rgopi2win/32/27126_2.png) [@rgopi2win](https://discuss.elastic.co/u/rgopi2win)\
**Post date:** [January 23, 2018, 5:04am UTC](https://discuss.elastic.co/t/to-get-end-date-of-week-in-date-histogram/116591/1 "2018-01-23T05:04:01Z")

</div>

Hi Team,

I am using date\_histogram type of aggregation for aggregating month level data and interval as Week(1w). Now, In the response 'key' value comes as start date of the week. But I would like to get end date of the week in 'key'. Could you please help.

eg.,  
The aggregation query I am using,

"aggs": {  
"Weekly\_Counts": {  
"date\_histogram": {  
"field": "created",  
"interval": "1w",  
"format":"yyyy-MM-dd E",  
"time\_zone":"Asia/Calcutta",  
"min\_doc\_count": 1  
}  
}  
}

the output i am getting like below. In 'key; the time is of start date of the week. Instead I would like to get end date of the week. Would you please help.

{  
....  
"aggregations": {  
"Weekly\_Counts": {  
"buckets": [  
{  
"key\_as\_string": "2018-01-01 Mon",  
"key": 1514745000000,  
"doc\_count": 7672  
},  
{  
"key\_as\_string": "2018-01-08 Mon",  
"key": 1515349800000,  
"doc\_count": 7754  
},  
{  
"key\_as\_string": "2018-01-15 Mon",  
"key": 1515954600000,  
"doc\_count": 7643  
}  
]  
}  
}  
}

Expectation:

In key, I would like to get the end date of the week as "2018-01-07 Sun"

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [January 23, 2018, 6:12pm UTC](https://discuss.elastic.co/t/to-get-end-date-of-week-in-date-histogram/116591/2 "2018-01-23T18:12:55Z")

</div>

This feature isn't supported unfortunately.

---

<div class="post-metadata">

**Author:** ![rgopi2win](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rgopi2win/32/27126_2.png) [@rgopi2win](https://discuss.elastic.co/u/rgopi2win)\
**Post date:** [January 30, 2018, 12:02pm UTC](https://discuss.elastic.co/t/to-get-end-date-of-week-in-date-histogram/116591/3 "2018-01-30T12:02:03Z")

</div>

Thank you jpountz. In following with your answer, having another doubt. shall I able to get the start date and end date in key like  
"key\_as\_string": "2018-01-15 - 2018-01-21".

We know in date range its possible. But there the limitation is we need to specify range for every bucket.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [February 1, 2018, 1:25pm UTC](https://discuss.elastic.co/t/to-get-end-date-of-week-in-date-histogram/116591/4 "2018-02-01T13:25:40Z")

</div>

I opened [https://github.com/elastic/elasticsearch/issues/28479](https://github.com/elastic/elasticsearch/issues/28479) to discuss it.

---

<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:** [March 1, 2018, 1:25pm UTC](https://discuss.elastic.co/t/to-get-end-date-of-week-in-date-histogram/116591/5 "2018-03-01T13:25:40Z")

</div>

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