# Timezone in range query builder for epoch timestamp

**URL:** <https://discuss.elastic.co/t/timezone-in-range-query-builder-for-epoch-timestamp/111940>\
**Category:** Elasticsearch\
**Created:** [December 15, 2017, 9:52am UTC](https://discuss.elastic.co/t/timezone-in-range-query-builder-for-epoch-timestamp/111940 "2017-12-15T09:52:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpmiitian](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@jpmiitian](https://discuss.elastic.co/u/jpmiitian)\
**Post date:** [December 15, 2017, 9:52am UTC](https://discuss.elastic.co/t/timezone-in-range-query-builder-for-epoch-timestamp/111940/1 "2017-12-15T09:52:00Z")

</div>

Hi

I have timestamp field in the ES Doc which has epoch timestamp UTC [long value].  
Ques :

1. How can I retrieve data in other time zone from the epoch timestamps in ES.

2. As we have support in DateHistogramAggregationBuilder for time zone,  
Do we have similar support for time range query builder ?

---

<div class="post-metadata">

**Author:** ![jpmiitian](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@jpmiitian](https://discuss.elastic.co/u/jpmiitian)\
**Post date:** [December 20, 2017, 7:44am UTC](https://discuss.elastic.co/t/timezone-in-range-query-builder-for-epoch-timestamp/111940/2 "2017-12-20T07:44:40Z")

</div>

@cbuescher Any idea about this OR Is there way to retrieve dayOfWeek from timestamp[which is in UTC] to some other timezone .

Thanks

---

<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:** [January 4, 2018, 4:36pm UTC](https://discuss.elastic.co/t/timezone-in-range-query-builder-for-epoch-timestamp/111940/3 "2018-01-04T16:36:28Z")

</div>

Hi @jpmiitian,

finally found some time to try this, sorry for the delay in getting back. Timezones don't work with "epoch\_millis" format in range, but you can specify another format in the range query, even if the field you query has "epoch\_millis" format. I just tried the following in ES 6.1.1:

```auto
GET /my_index/_mapping

{
  "my_index": {
    "mappings": {
      "my_type": {
        "properties": {
          "date": {
            "type": "date",
            "format": "epoch_millis"
          }
        }
      }
    }
  }
}

PUT /my_index/my_type/1
{
  "date" : 1514761200000 <-- Thats 2018-01-01 00:00:00 in UTC+1
}

GET /my_index/_search
{
    "query": {
        "range" : {
            "date" : {
                "gte": "2018-01-01", 
                "lte": "2018-01-02",
                "format": "yyyy-MM-dd", 
                "time_zone": "+01:00"
            }
        }
    }
}

"hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "my_index",
        "_type": "my_type",
        "_id": "1",
        "_score": 1,
        "_source": {
          "date": 1514761200000
        }
      }
    ]
  }

```

With timezone "-01:00" there are no hits, so the zone takes effect.  
I only tried the rest endpoint but this should also apply to the JAVA Api.

> [@jpmiitian](#):
>
> Is there way to retrieve dayOfWeek from timestamp

I think you might be able to use scripts for doing this in aggregations, but this depends very much on the use case I think. I'd open a separate issue for this since I'm not too familiar with this myself.

---

<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 1, 2018, 4:36pm UTC](https://discuss.elastic.co/t/timezone-in-range-query-builder-for-epoch-timestamp/111940/4 "2018-02-01T16:36:56Z")

</div>

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