# Hour Scripted Field

**URL:** https://discuss.elastic.co/t/hour-scripted-field/263416
**Category:** Kibana
**Tags:** painless
**Created:** [February 5, 2021, 3:23pm UTC](https://discuss.elastic.co/t/hour-scripted-field/263416 "2021-02-05T15:23:22Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![stevezemlicka](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stevezemlicka](https://discuss.elastic.co/u/stevezemlicka)
#### Post date: [February 9, 2021, 10:53pm UTC](https://discuss.elastic.co/t/hour-scripted-field/263416/5 "2021-02-09T22:53:33Z")

</div>

For those that come across this in the future, I had an issue with the previous solution and timezone. Seems this was matching UTC which didn't align with the expected output due to how timezones are handled with scripted fields. What ultimately worked was:

> return LocalDateTime.ofInstant(Instant.ofEpochMilli(doc['@timestamp'].value.millis),ZoneId.of('America/Chicago')).getHour()

> [@ES 6.0 - Scripted Field HourOfDay with Timezone - error](https://discuss.elastic.co/t/es-6-0-scripted-field-hourofday-with-timezone-error/107792):
>
> Hello, First Post Here, I will try to do my best to make a clear presentation. I recently upgraded ELK on my UAT node from 5.6 to 6.0 OS : 2012r2 ; single node. ELK : 6.0.0 Java : 1.8.0\_151 I was running a painless scripted field pretty well on 5.6.0 to deduce HourOfDay, as follow : Name : HourOfDay Script : LocalDateTime.ofInstant(Instant.ofEpochMilli(doc['@timestamp'].value),ZoneId.of('Europe/Paris')).getHour() I used this script because of the Timezone I'm using : Europe/Paris ; it…

---

_[View the full topic](https://discuss.elastic.co/t/hour-scripted-field/263416)._
