# ElasticSearch date rangequery affected by TimeZone

**URL:** <https://discuss.elastic.co/t/elasticsearch-date-rangequery-affected-by-timezone/43225>\
**Category:** Elasticsearch\
**Created:** [March 2, 2016, 10:11am UTC](https://discuss.elastic.co/t/elasticsearch-date-rangequery-affected-by-timezone/43225 "2016-03-02T10:11:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sosoda](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sosoda](https://discuss.elastic.co/u/sosoda)\
**Post date:** [March 2, 2016, 10:11am UTC](https://discuss.elastic.co/t/elasticsearch-date-rangequery-affected-by-timezone/43225/1 "2016-03-02T10:11:09Z")

</div>

I tried for several times,but still confused.  
At first the mapping of date field is  
{  
"createdAt" : {  
"type" : "date",  
"format" : "yyyy-MM-dd HH:mm:ss"  
}  
}  
when I query with java, I use SimpleDateFormat like

```
SimpleDateFormat smf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String format = smf.format(date);

```

the result is affected by TimeZone.  
And I try store the date field with format like "yyyy-MM-dd hh:mm:ss Z" and without [format.In](http://format.In) this time , I get the correct result. So what happend in the format thing?

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [March 2, 2016, 3:31pm UTC](https://discuss.elastic.co/t/elasticsearch-date-rangequery-affected-by-timezone/43225/2 "2016-03-02T15:31:50Z")

</div>

Hi,  
which version of Elasticsearch are you using? That said, dates are internally stored as long  
values representing milliseconds-since-the-epoch in UTC. So if your date are not UTC, you can either convert them in your application or specify the time zone in your date format string.

The [Range Query](https://www.elastic.co/guide/en/elasticsearch/reference/2.2/mapping-date-format.html) also supports a `time_zone` parameter, but this will only affect the bounds you apply in the query itself, not the stored values.

---

<div class="post-metadata">

**Author:** ![sosoda](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@sosoda](https://discuss.elastic.co/u/sosoda)\
**Post date:** [March 3, 2016, 3:43am UTC](https://discuss.elastic.co/t/elasticsearch-date-rangequery-affected-by-timezone/43225/3 "2016-03-03T03:43:49Z")

</div>

Thank you for reply.：D  
I'm using version 1.2, quite old one.  
I think I know what happened before.  
The date value I stored in ES when I'm using Java Client And save with Java.util.Date. It is timestamp acturally.  
When I'm doing the query, I'm using the data value like `2016-03-03 00:00:00` .When ES convert this into timeStamp,  
it automaticly add "+00:00". I intent to search with a different timezone.  
Is this right?

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [March 3, 2016, 8:53am UTC](https://discuss.elastic.co/t/elasticsearch-date-rangequery-affected-by-timezone/43225/4 "2016-03-03T08:53:42Z")

</div>

Hi Sosoda,

ES doesn't add anything to your dates, it rather assumes it is UTC when you don't specify any other timezone. I'm not exactly sure, but it seems the `time_zone` option has been added to the range query in ES 1.4.

---

<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:** [July 5, 2017, 11:11pm UTC](https://discuss.elastic.co/t/elasticsearch-date-rangequery-affected-by-timezone/43225/5 "2017-07-05T23:11:44Z")

</div>


