# Date Range Not Working with Now

**URL:** <https://discuss.elastic.co/t/date-range-not-working-with-now/268825>\
**Category:** Elasticsearch\
**Created:** [March 30, 2021, 5:03pm UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825 "2021-03-30T17:03:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohan\_5894](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohan_5894/32/67407_2.png) [@rohan\_5894](https://discuss.elastic.co/u/rohan_5894)\
**Post date:** [March 30, 2021, 5:03pm UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/1 "2021-03-30T17:03:57Z")

</div>

# I am trying to show only those documents where published\_at date is less than now-7d/d.

#It seems ES is not working correctly here. I tried with an example of showing documents which are having published\_at filed greater than current datetime. Even though the published\_at field is not greater than now but i still see one document in results. I am not sure what is happening here.

Please also note that then i am using "2021-03-30 20:20:49" instead of "now" then it is working. Something is wrong with now.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 30, 2021, 7:05pm UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/2 "2021-03-30T19:05:41Z")

</div>

Or may be now is not what you think it is.  
I mean that may be you did not set a timezone anywhere and now actually represents now UTC based.

---

<div class="post-metadata">

**Author:** ![rohan\_5894](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohan_5894/32/67407_2.png) [@rohan\_5894](https://discuss.elastic.co/u/rohan_5894)\
**Post date:** [March 31, 2021, 8:29am UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/3 "2021-03-31T08:29:32Z")

</div>

Thanks, I tried supplying time\_stamp as well but no luck

`GET ak_questions/_search { "sort": [{ "created_at": { "order": "desc" } }], "query": { "bool": { "must": { "range": { "published_at": { "time_zone": "+05:30", "lte": "now" } } } } } }`

---

<div class="post-metadata">

**Author:** ![rohan\_5894](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohan_5894/32/67407_2.png) [@rohan\_5894](https://discuss.elastic.co/u/rohan_5894)\
**Post date:** [March 31, 2021, 8:31am UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/4 "2021-03-31T08:31:08Z")

</div>

The above query is not showing me the latest published question even though it is less than current timestamp using now.

---

<div class="post-metadata">

**Author:** ![rohan\_5894](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohan_5894/32/67407_2.png) [@rohan\_5894](https://discuss.elastic.co/u/rohan_5894)\
**Post date:** [March 31, 2021, 8:35am UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/5 "2021-03-31T08:35:17Z")

</div>

Is there a way i can print what timestamp now is returning?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 31, 2021, 8:55am UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/6 "2021-03-31T08:55:18Z")

</div>

I meant the timezone in the source data not when you are querying.  
What does a typical document look like?

---

<div class="post-metadata">

**Author:** ![rohan\_5894](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohan_5894/32/67407_2.png) [@rohan\_5894](https://discuss.elastic.co/u/rohan_5894)\
**Post date:** [March 31, 2021, 9:09am UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/7 "2021-03-31T09:09:48Z")

</div>

I have not specified timezone in fields mapping. Kindly check the attached screenshot ![Screenshot 2021-03-31 at 2.38.36 PM](https://us1.discourse-cdn.com/elastic/original/3X/7/5/753ca4d8f1e8c6a42ec383140916618b05999ad3.png)

---

<div class="post-metadata">

**Author:** ![rohan\_5894](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohan_5894/32/67407_2.png) [@rohan\_5894](https://discuss.elastic.co/u/rohan_5894)\
**Post date:** [March 31, 2021, 9:18am UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/8 "2021-03-31T09:18:03Z")

</div>

I think my Kibana is using default timezone of IST and when querying then it is resolving published\_at timestamp to +5:30, because when i specify time\_zone in query then the document doesn't match against 2021-03-31 13:57:52 even as it is adding 5:30 hours to published\_at.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 31, 2021, 11:50am UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/9 "2021-03-31T11:50:38Z")

</div>

Please don't post images of text as they are hard to read, may not display correctly for everyone, and are not searchable.

Instead, paste the text and format it with `</>` icon or pairs of triple backticks (```), and check the preview window to make sure it's properly formatted before posting it. This makes it more likely that your question will receive a useful answer.

It would be great if you could update your post to solve this.

As far as I can see you are not specifying a timezone in your dates in the document. That's why you have incorrect results I think.

---

<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:** [April 28, 2021, 11:51am UTC](https://discuss.elastic.co/t/date-range-not-working-with-now/268825/10 "2021-04-28T11:51:26Z")

</div>

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