# Scripted Field not working

**URL:** https://discuss.elastic.co/t/scripted-field-not-working/237365
**Category:** Kibana
**Created:** [June 16, 2020, 9:26pm UTC](https://discuss.elastic.co/t/scripted-field-not-working/237365 "2020-06-16T21:26:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![N\_P](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/n_p/32/48731_2.png) [@N\_P](https://discuss.elastic.co/u/N_P)
#### Post date: [June 16, 2020, 9:27pm UTC](https://discuss.elastic.co/t/scripted-field-not-working/237365/1 "2020-06-16T21:27:00Z")

</div>

Hi Folks,

I am trying to make a scripted field that takes the "@timestamp" field converts it to PST (pacific standard time) and then extracts the hour.

Can anyone see where I am going wrong with the below scripted field?

```auto
String datetime = doc['@timestamp'].value; 
ZonedDateTime utc = ZonedDateTime.parse(datetime);
ZonedDateTime pst = utc.withZoneSameInstant(ZoneId.of('America/Los_Angeles'));
return pst.getHour();

```

---

<div class="post-metadata">

### Author: ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)
#### Post date: [June 18, 2020, 7:38am UTC](https://discuss.elastic.co/t/scripted-field-not-working/237365/2 "2020-06-18T07:38:31Z")

</div>

> [@N\_P](#):
>
> ```auto
> String datetime = doc['@timestamp'].value; 
> ZonedDateTime utc = ZonedDateTime.parse(datetime);
> ZonedDateTime pst = utc.withZoneSameInstant(ZoneId.of('America/Los_Angeles'));
> return pst.getHour();
> 
> ```

Hi

Here we go:

```
ZonedDateTime utc = doc['@timestamp'].value;
ZonedDateTime pst = utc.withZoneSameInstant(ZoneId.of('America/Los_Angeles'));
return pst.getHour();

```

You don't need to parse the value, it's already a **ZonedDateTime**  
Best,  
Matthias

---

<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 16, 2020, 7:38am UTC](https://discuss.elastic.co/t/scripted-field-not-working/237365/3 "2020-07-16T07:38:44Z")

</div>

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