# Extracting MonthOfYear In Kibana Scripted Field

**URL:** <https://discuss.elastic.co/t/extracting-monthofyear-in-kibana-scripted-field/218322>\
**Category:** Kibana\
**Created:** [February 7, 2020, 10:43am UTC](https://discuss.elastic.co/t/extracting-monthofyear-in-kibana-scripted-field/218322 "2020-02-07T10:43:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramya\_Tanikanti](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@Ramya\_Tanikanti](https://discuss.elastic.co/u/Ramya_Tanikanti)\
**Post date:** [February 7, 2020, 10:43am UTC](https://discuss.elastic.co/t/extracting-monthofyear-in-kibana-scripted-field/218322/1 "2020-02-07T10:43:15Z")

</div>

The following Scripted Field code is throwing an error,

def month = doc['signed\_date'].date.monthOfYear;

I want to extract the months as a separate column. What am I doing wrong here?

Kindly help.

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [February 11, 2020, 1:28pm UTC](https://discuss.elastic.co/t/extracting-monthofyear-in-kibana-scripted-field/218322/2 "2020-02-11T13:28:23Z")

</div>

`monthOfYear` is not a function that is available in painless. You can access date pieces with the functions at [https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-datetime.html#\_datetime\_pieces](https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-datetime.html#_datetime_pieces).

`doc['timestamp'].value.getMonthValue()` is an example of a scripted field that returns the month of the year from the Kibana's web logs sample data set.

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [February 11, 2020, 1:32pm UTC](https://discuss.elastic.co/t/extracting-monthofyear-in-kibana-scripted-field/218322/3 "2020-02-11T13:32:09Z")

</div>

If you want the month as a string instead of a number, you could use `doc['timestamp'].value.getMonth()`. That method is not listed in the docs but the docs say the datetime type is `ZonedDateTime` and looking at the [Java docs for ZonedDateTime](https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html) shows some additional getter methods not mentioned in the painless documentation.

---

<div class="post-metadata">

**Author:** ![Ramya\_Tanikanti](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@Ramya\_Tanikanti](https://discuss.elastic.co/u/Ramya_Tanikanti)\
**Post date:** [February 11, 2020, 1:44pm UTC](https://discuss.elastic.co/t/extracting-monthofyear-in-kibana-scripted-field/218322/4 "2020-02-11T13:44:04Z")

</div>

@Nathan_Reese Thank you soo much. 😊 Very useful doc!!

---

<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:** [March 10, 2020, 1:44pm UTC](https://discuss.elastic.co/t/extracting-monthofyear-in-kibana-scripted-field/218322/5 "2020-03-10T13:44:07Z")

</div>

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