# Elasticsearch Timezone error?

**URL:** <https://discuss.elastic.co/t/elasticsearch-timezone-error/75881>\
**Category:** Elasticsearch\
**Created:** [February 21, 2017, 1:06pm UTC](https://discuss.elastic.co/t/elasticsearch-timezone-error/75881 "2017-02-21T13:06:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [February 21, 2017, 1:06pm UTC](https://discuss.elastic.co/t/elasticsearch-timezone-error/75881/1 "2017-02-21T13:06:14Z")

</div>

In my mapping i defined

```
"Time": {
                  "type": "date",
                  "format": "strict_date_optional_time||epoch_millis"

```

When i used the following query

```
"range": {
                "Time": {
                  "gt": "now-1h"
                }
              }

```

Rather than showing the documents for last hour it showing the documents for past 3-4 hours.

My documents has Time field like this `"Time": "2017-02-10T10:07:04.4367673+00:00"`  
I think it is in UTC format.  
Thanks..

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [February 21, 2017, 7:00pm UTC](https://discuss.elastic.co/t/elasticsearch-timezone-error/75881/2 "2017-02-21T19:00:06Z")

</div>

Yes, the date is stored in UTC format. The reason why I think you are seeing the past 3 - 4 hours is you are missing a "lt". A range should contain a gt and lt if you want to get a specific set of documents within a set timeframe - like the last hour.

"query": {  
"range": {  
"mydate": {  
"gt": "now-10h",  
"lt" : "now-9h"  
}  
}

Depending on the version of ES you are using, you can also use aggregation date\_range / to & from / or you can store your dates in the timezone you want.

For example:

POST mytime2/mytimer  
{  
"mynum" : "2017-02-21T12:02:04.4367673-08:00"

}

See that in the last bit I put -08:00 , which converts the UTC to PST.

---

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [February 22, 2017, 5:46am UTC](https://discuss.elastic.co/t/elasticsearch-timezone-error/75881/3 "2017-02-22T05:46:24Z")

</div>

Thankyou jkuang 🙂

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [February 22, 2017, 5:19pm UTC](https://discuss.elastic.co/t/elasticsearch-timezone-error/75881/4 "2017-02-22T17:19:41Z")

</div>

😃 No problem, you're welcome.

---

<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 22, 2017, 5:19pm UTC](https://discuss.elastic.co/t/elasticsearch-timezone-error/75881/5 "2017-03-22T17:19:45Z")

</div>

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