# Hour Extraction

**URL:** https://discuss.elastic.co/t/hour-extraction/206624
**Category:** Elasticsearch
**Tags:** painless
**Created:** [November 5, 2019, 2:24pm UTC](https://discuss.elastic.co/t/hour-extraction/206624 "2019-11-05T14:24:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Jim\_Thunder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jim_thunder/32/45439_2.png) [@Jim\_Thunder](https://discuss.elastic.co/u/Jim_Thunder)
#### Post date: [November 5, 2019, 2:24pm UTC](https://discuss.elastic.co/t/hour-extraction/206624/1 "2019-11-05T14:24:07Z")

</div>

Hello!

I am trying to extract the hour from the timestamp using a scripted field. I haven't a clue how. Any thoughts?

The reason I need to do it in a scripted field is because of the timezone change. When I pull the hour out in logstash I get UTC time and not Amercia/Chicago.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [November 6, 2019, 9:33am UTC](https://discuss.elastic.co/t/hour-extraction/206624/2 "2019-11-06T09:33:25Z")

</div>

on top of my head

```auto
doc['timestamp_field'].value.getHour()

```

however this hour will be in UTC as well, as it is accessing the value stored in kibana. Not sure about your use-case. Maybe it is sufficient to configure the timezone in kibana?

---

<div class="post-metadata">

### Author: ![Jim\_Thunder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jim_thunder/32/45439_2.png) [@Jim\_Thunder](https://discuss.elastic.co/u/Jim_Thunder)
#### Post date: [November 6, 2019, 5:38pm UTC](https://discuss.elastic.co/t/hour-extraction/206624/3 "2019-11-06T17:38:33Z")

</div>

The code worked but you're right, still UTC. How can I get the hour from the Time that the Kibana got the record?

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [November 7, 2019, 8:51am UTC](https://discuss.elastic.co/t/hour-extraction/206624/4 "2019-11-07T08:51:52Z")

</div>

you could retrieve the zoneoffset. The object being returned is a `JodaCompatibleZonedDateTime`, see [https://www.elastic.co/guide/en/elasticsearch/painless/7.4/painless-api-reference-shared-org-elasticsearch-script.html#painless-api-reference-shared-JodaCompatibleZonedDateTime](https://www.elastic.co/guide/en/elasticsearch/painless/7.4/painless-api-reference-shared-org-elasticsearch-script.html#painless-api-reference-shared-JodaCompatibleZonedDateTime)

--Alex

---

<div class="post-metadata">

### Author: ![Jim\_Thunder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jim_thunder/32/45439_2.png) [@Jim\_Thunder](https://discuss.elastic.co/u/Jim_Thunder)
#### Post date: [November 11, 2019, 4:34pm UTC](https://discuss.elastic.co/t/hour-extraction/206624/5 "2019-11-11T16:34:32Z")

</div>

I already have a zone offset (I think?) It comes out to -5 hours.

Something else I did find though: Kibana auto detects dates/times and THAT is what my underlying problem is. Do you know how I can tell kibana to NOT auto detect times/dates and just write to each field as a string?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/b/db3cc496f5eef4fae76606ce48e8d1eedff95c41.png)

I want that "TYPE" for SMF30DTE to be a string NOT a date (note: I manually changed the Format to string, was blank before).

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [November 20, 2019, 3:19pm UTC](https://discuss.elastic.co/t/hour-extraction/206624/6 "2019-11-20T15:19:11Z")

</div>

indeed, you can format fields in kibana, see [https://www.elastic.co/guide/en/kibana/7.4/managing-fields.html](https://www.elastic.co/guide/en/kibana/7.4/managing-fields.html)

---

<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: [December 18, 2019, 3:19pm UTC](https://discuss.elastic.co/t/hour-extraction/206624/7 "2019-12-18T15:19:23Z")

</div>

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