# Timezone-affected date histogram

**URL:** <https://discuss.elastic.co/t/timezone-affected-date-histogram/154822>\
**Category:** Elasticsearch\
**Created:** [October 31, 2018, 11:13am UTC](https://discuss.elastic.co/t/timezone-affected-date-histogram/154822 "2018-10-31T11:13:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vorta](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@Vorta](https://discuss.elastic.co/u/Vorta)\
**Post date:** [October 31, 2018, 11:13am UTC](https://discuss.elastic.co/t/timezone-affected-date-histogram/154822/1 "2018-10-31T11:13:11Z")

</div>

Hello!

I have a following query coming from PHP:

```
{
  "size": 0,
  "aggs": {
    "statuses_histogram": {
      "date_histogram": {
        "field": "created_at",
        "interval": "1d",
        "min_doc_count": 0,
        "extended_bounds": {
          "min": "2018-10-01T00:00:00+02:00",
          "max": "2018-10-09T23:59:59+02:00"
        }
      },
      "aggs": {
        "statuses_histogram": {
          "terms": {
            "field": "status",
            "order": {
              "_key": "asc"
            }
          }
        }
      }
    }
  }
}

```

This should return a date aggregation of how many times a certain status repeated per day. It should have 7 days as a result, however, the result I'm getting contains 31 day and it goes from `2018-09-30T00:00:00.000Z` to `2018-10-30T00:00:00.000Z`. How is this possible? What am I doing wrong?

It is important that the days in the aggregation are matched to the user's timezone, not UTC. I've got users from Australia and having date aggregations by UTC timezone makes no sense for them.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [October 31, 2018, 11:43am UTC](https://discuss.elastic.co/t/timezone-affected-date-histogram/154822/2 "2018-10-31T11:43:30Z")

</div>

`extended_bounds` does not filter the data in your index, it only allows to extend the bounds of your aggregation if needed. You need to add a range query to filter the data you are aggregating.

---

<div class="post-metadata">

**Author:** ![Vorta](https://avatars.discourse-cdn.com/v4/letter/v/ecd19e/32.png) [@Vorta](https://discuss.elastic.co/u/Vorta)\
**Post date:** [October 31, 2018, 11:47am UTC](https://discuss.elastic.co/t/timezone-affected-date-histogram/154822/3 "2018-10-31T11:47:27Z")

</div>

Thank you!

All questions from the original post resolved with the following query:

```
{
  "size": 0,
  "aggs": {
    "statuses_histogram": {
      "date_histogram": {
        "field": "created_at",
        "interval": "1d",
        "min_doc_count": 0,
        "time_zone": "Europe/Zagreb",
        "extended_bounds": {
          "min": "2018-10-01T00:00:00+02:00",
          "max": "2018-10-09T23:59:59+02:00"
        }
      },
      "aggs": {
        "statuses_histogram": {
          "terms": {
            "field": "status",
            "order": {
              "_key": "asc"
            }
          }
        }
      }
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "created_at": {
              "gte": "2018-10-01T00:00:00+02:00",
              "lte": "2018-10-09T23:59:59+02:00"
            }
          }
        }
      ]
    }
  }
}

```

(using bool query because other parameters not relevant to this topic are being used as well)

---

<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:** [November 28, 2018, 11:47am UTC](https://discuss.elastic.co/t/timezone-affected-date-histogram/154822/4 "2018-11-28T11:47:28Z")

</div>

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