# Kibana - Scripted Field TimeZone in Month

**URL:** <https://discuss.elastic.co/t/kibana-scripted-field-timezone-in-month/209314>\
**Category:** Kibana\
**Created:** [November 25, 2019, 1:44pm UTC](https://discuss.elastic.co/t/kibana-scripted-field-timezone-in-month/209314 "2019-11-25T13:44:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Almeida1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafael_almeida1/32/56779_2.png) [@Rafael\_Almeida1](https://discuss.elastic.co/u/Rafael_Almeida1)\
**Post date:** [November 25, 2019, 1:44pm UTC](https://discuss.elastic.co/t/kibana-scripted-field-timezone-in-month/209314/1 "2019-11-25T13:44:28Z")

</div>

Hi, I'm trying use scripted fields to get day, month and year of a date field but get some trouble over month field. I have the following scenario:

First Test:

Timezone of Server : UTC-3 (America/Fortaleza)  
Timezone of Kibana Advanced Settings: UTC (Standard)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/7/475d4b9b32ab22275b795f3fde540b832b0741c3.png)

Time Day Month ID  
01/11/2019 00:03:00 1 November 21769  
31/10/2019 23:58:00 31 October 21768

But expected  
Time Day Month ID  
31/10/2019 21:03:00 31 October 21769  
31/10/2019 20:58:00 31 October 21768

Second Test:

Timezone of Server : UTC-3 (America/Fortaleza)  
Timezone of Kibana Advanced Settings: UTC-3 (America/Fortaleza)

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

Time Day Month ID  
31/10/2019 21:03:00 1 November 21769  
31/10/2019 20:58:00 31 October 21768

But expected  
Time Day Month ID  
31/10/2019 21:03:00 31 October 21769  
31/10/2019 20:58:00 31 October 21768

Third Test:

Timezone of Server : UTC-3 (America/Fortaleza)  
Timezone of Kibana Advanced Settings: UTC-3 (America/Fortaleza)  
Scripted Field in Index Patterns  
def day = LocalDateTime.ofInstant(Instant.ofEpochMilli(doc['datetime'].value.millis),ZoneId.of('UTC-3')).dayOfMonth; return day;

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/1/41841086a7150552b1c4695e81803e23b41fefdb.png)

Time Day Month ID  
31/10/2019 21:03:00 31 November 21769  
31/10/2019 20:58:00 31 October 21768

But expected  
Time Day Month ID  
31/10/2019 21:03:00 31 October 21769  
31/10/2019 20:58:00 31 October 21768

So my ask is how define timeZone in scripted field of month or other solution option?

I use this scripted field for month

def month = doc['datetime'].value.monthOfYear; def months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; return months[month-1];

---

<div class="post-metadata">

**Author:** ![Rafael\_Almeida1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafael_almeida1/32/56779_2.png) [@Rafael\_Almeida1](https://discuss.elastic.co/u/Rafael_Almeida1)\
**Post date:** [November 25, 2019, 6:11pm UTC](https://discuss.elastic.co/t/kibana-scripted-field-timezone-in-month/209314/2 "2019-11-25T18:11:21Z")

</div>

I'm trying apply this scripted field but nothing changes

int year = doc['data'].value.year;  
int month = doc['data'].value.monthOfYear;  
int day = doc['data'].value.dayOfMonth;  
int hour = doc['data'].value.hourOfDay;  
int minutes = doc['data'].value.minuteOfHour;  
int seconds = doc['data'].value.secondOfMinute;  
int nanos = 0;  
ZonedDateTime zdt = ZonedDateTime.of(year, month, day, hour, minutes, seconds, nanos, ZoneId.of('UTC-3'));  
int tzyear = zdt.getYear();  
int tzmonth = zdt.getMonthValue();  
int tzday = zdt.getDayOfMonth();  
int tzhour = zdt.getHour();  
int tzminutes = zdt.getMinute();  
int tzseconds = zdt.getSecond();  
int tznanos = zdt.getNano();  
def months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; return months[tzmonth-1];

---

<div class="post-metadata">

**Author:** ![Rafael\_Almeida1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafael_almeida1/32/56779_2.png) [@Rafael\_Almeida1](https://discuss.elastic.co/u/Rafael_Almeida1)\
**Post date:** [November 25, 2019, 6:43pm UTC](https://discuss.elastic.co/t/kibana-scripted-field-timezone-in-month/209314/3 "2019-11-25T18:43:32Z")

</div>

int year = doc['data'].value.year;  
int month = doc['data'].value.monthOfYear;  
int day = doc['data'].value.dayOfMonth;  
int hour = doc['data'].value.hourOfDay;  
int minutes = doc['data'].value.minuteOfHour;  
int seconds = doc['data'].value.secondOfMinute;  
int nanos = 0;  
ZonedDateTime zdt = ZonedDateTime.of(year, month, day, hour, minutes, seconds, nanos, ZoneId.of('UTC'));

ZonedDateTime updatedZdt = zdt.minusHours(3);

int tzyear = updatedZdt.getYear();  
int tzmonth = updatedZdt.getMonthValue();  
int tzday = updatedZdt.getDayOfMonth();  
int tzhour = updatedZdt.getHour();  
int tzminutes = updatedZdt.getMinute();  
int tzseconds = updatedZdt.getSecond();  
int tznanos = updatedZdt.getNano();  
def months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; return months[tzmonth-1];

I don't know but this scripted field works

---

<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 23, 2019, 6:43pm UTC](https://discuss.elastic.co/t/kibana-scripted-field-timezone-in-month/209314/4 "2019-12-23T18:43:39Z")

</div>

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