# Week of the year aggregation

**URL:** <https://discuss.elastic.co/t/week-of-the-year-aggregation/150113>\
**Category:** Elasticsearch\
**Created:** [September 27, 2018, 5:01am UTC](https://discuss.elastic.co/t/week-of-the-year-aggregation/150113 "2018-09-27T05:01:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulohss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paulohss/32/4756_2.png) [@paulohss](https://discuss.elastic.co/u/paulohss)\
**Post date:** [September 27, 2018, 5:01am UTC](https://discuss.elastic.co/t/week-of-the-year-aggregation/150113/1 "2018-09-27T05:01:03Z")

</div>

Hi guys,

I'm trying to get the week of the years using a painless script (below)

```
def date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(doc['DATE_FIELD'].value.millis), ZoneId.of(UTC)); 
DayOfWeek dayOfWeek = DayOfWeek.valueOf('MONDAY');
date = date.with(TemporalAdjusters.previousOrSame(dayOfWeek)).plusWeeks(1); 
return date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);

```

**Expected result** for Week 35 is these dates 27th August - 2 September  
**Current result** for Week 35 (see screenshot) is these dates 20th August - 26 August

Any idea what I might be missing here?

Cheers

---

<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:** [October 25, 2018, 5:01am UTC](https://discuss.elastic.co/t/week-of-the-year-aggregation/150113/2 "2018-10-25T05:01:09Z")

</div>

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