# Date range with weekyear\_week format (xxxx-'W'ww)

**URL:** <https://discuss.elastic.co/t/date-range-with-weekyear-week-format-xxxx-www/166187>\
**Category:** Elasticsearch\
**Created:** [January 29, 2019, 2:16pm UTC](https://discuss.elastic.co/t/date-range-with-weekyear-week-format-xxxx-www/166187 "2019-01-29T14:16:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julien\_Tanguy](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@Julien\_Tanguy](https://discuss.elastic.co/u/Julien_Tanguy)\
**Post date:** [January 29, 2019, 2:16pm UTC](https://discuss.elastic.co/t/date-range-with-weekyear-week-format-xxxx-www/166187/1 "2019-01-29T14:16:35Z")

</div>

Hi,

I have a problem, and a solution. But maybe there is a better solution.

**My problem:**  
I need to make a query with a date range `{"lt": "2019-W04", "gte": "2019-W03"}`  
The date field has `xxxx-'W'ww` as date format.  
But the result of this query is a document with `2019-W04` as date.  
The epoch timestamp in this document is `1548028800000` so 2019-01-21, the first day of the week 4 of 2019, cool.  
But when I did an explain with this query, on the found document, it used this range: `[1547683200000 TO 1548287999999]`, so from `2019-01-17` (thursday of the week 3) to `2019-01-23` (wednesday of the week 4).

**Question:**  
Why the range filter use the middle of the week to make the query ?

**My solution:**  
Round date values with `||/w`  
`{"lt": "2019-W04||/w", "gte": "2019-W03||/w"}`  
Range from explain: `[1547424000000 TO 1548028799999]`, so from `2019-01-14` (monday of the week 3) to `2019-01-20` (sunday of the week 3), youhou 🙂

Do you have a better solution ?

---

<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:** [February 26, 2019, 2:23pm UTC](https://discuss.elastic.co/t/date-range-with-weekyear-week-format-xxxx-www/166187/2 "2019-02-26T14:23:55Z")

</div>

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