# Aggs Painless DateTime Modify inline

**URL:** <https://discuss.elastic.co/t/aggs-painless-datetime-modify-inline/237162>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [June 15, 2020, 3:37pm UTC](https://discuss.elastic.co/t/aggs-painless-datetime-modify-inline/237162 "2020-06-15T15:37:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndyS](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@AndyS](https://discuss.elastic.co/u/AndyS)\
**Post date:** [June 15, 2020, 3:37pm UTC](https://discuss.elastic.co/t/aggs-painless-datetime-modify-inline/237162/1 "2020-06-15T15:37:21Z")

</div>

Hia,  
As per title I'm stuck with a painless timezone Q:

Customer, WebUI, tz UTC+5  
The WebUI issues a query and converts query to UTC  
Elastic processes in UTC and then aggs by hour and by minute

```
"aggs": {
	"time": {
		"terms": {
			"script": {
				"source": "doc['@timestamp'].value.getDayOfMonth()"
			}
		},
		"aggs": {
			"time": {
				"terms": {
					"script": {
						"source": "doc['@timestamp'].value.getHour()"
					}
				}
			}
		}
	}
},

```

The results accurately group into buckets

```
  "aggregations" : {
    "time" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "10",
          "doc_count" : 484318,
          "time" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "17",

```

But the reply to the WebUI is now in UTC. Converting from key:10 and key:17 is possible in JS, but fiddly (as it could be getDay() + getHour().... or getHour() + getMinute().

I suspect the cleanest way to do this is a tz modifier before the getHour() is issued. I've spent a few hours looking at Java/Painless but I'm struggling, every example I can find is fundamentally different, or I can't work out the alternative.

I guess the code would look something like:  
"source": "doc['@timestamp'].setTimeZone('America/Argentina/Buenos\_Aires').value.getHour()"

Any input much appreciated!

Thanks  
Andy

---

<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 13, 2020, 3:37pm UTC](https://discuss.elastic.co/t/aggs-painless-datetime-modify-inline/237162/2 "2020-07-13T15:37:29Z")

</div>

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