# Getting first 3 characters of month from date

**URL:** <https://discuss.elastic.co/t/getting-first-3-characters-of-month-from-date/305590>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [May 25, 2022, 10:15am UTC](https://discuss.elastic.co/t/getting-first-3-characters-of-month-from-date/305590 "2022-05-25T10:15:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![behappy\_alwayz0401](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/behappy_alwayz0401/32/105988_2.png) [@behappy\_alwayz0401](https://discuss.elastic.co/u/behappy_alwayz0401)\
**Post date:** [May 25, 2022, 10:15am UTC](https://discuss.elastic.co/t/getting-first-3-characters-of-month-from-date/305590/1 "2022-05-25T10:15:27Z")

</div>

How can we get only the first three characters of the month from a date field using a scripted field in kibana painless? Using getMonth() fetches the entire month. thanks

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [May 25, 2022, 11:25am UTC](https://discuss.elastic.co/t/getting-first-3-characters-of-month-from-date/305590/2 "2022-05-25T11:25:11Z")

</div>

Hi @behappy_alwayz0401,  
try this:

```auto
def month = doc['order_date'].value.getMonth().toString().substring(0,3);
return month;

```

---

<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:** [June 22, 2022, 11:26am UTC](https://discuss.elastic.co/t/getting-first-3-characters-of-month-from-date/305590/3 "2022-06-22T11:26:09Z")

</div>

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