# Runtime get month()

**URL:** <https://discuss.elastic.co/t/runtime-get-month/339721>\
**Category:** Elasticsearch\
**Tags:** runtime-fields\
**Created:** [July 31, 2023, 5:32pm UTC](https://discuss.elastic.co/t/runtime-get-month/339721 "2023-07-31T17:32:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Murilo\_Livorato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/murilo_livorato/32/123848_2.png) [@Murilo\_Livorato](https://discuss.elastic.co/u/Murilo_Livorato)\
**Post date:** [July 31, 2023, 5:32pm UTC](https://discuss.elastic.co/t/runtime-get-month/339721/1 "2023-07-31T17:32:53Z")

</div>

hello , I have this runtime -

```auto
GET my-index-000006-test/_search
{
  "runtime_mappings": {
        "day_of_week": {
        "type": "keyword",
        "script": {
          "source": "emit(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
        }
      }
  },
  "fields" : ["day_of_week"]
}

```

Its gives the day of the week from the timestamp -

```auto
  {
        "_index": "my-index-000006-test",
        "_id": "tUF9rIkB6LNnmdzdzkzz",
        "_score": 1,
        "_source": {
          "title": "three",
          "timestamp": "2021-01-04"
        },
        "fields": {
          "day_of_week": [
            "Monday"
          ]
        }
      },

```

does have any how to get the Month of the year ? I tryed like that -

```auto
GET my-index-000006-test/_search
{
  "runtime_mappings": {
        "month_of_year": {
        "type": "keyword",
        "script": {
          "source": "emit(doc['timestamp'].value.getMonth()"
        }
      }
  },
  "fields" : ["month_of_year"]
}

```

but didnt work

---

<div class="post-metadata">

**Author:** ![Alex\_Salgado-Elastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_salgado-elastic/32/103081_2.png) [@Alex\_Salgado-Elastic](https://discuss.elastic.co/u/Alex_Salgado-Elastic)\
**Post date:** [August 1, 2023, 3:07am UTC](https://discuss.elastic.co/t/runtime-get-month/339721/2 "2023-08-01T03:07:22Z")

</div>

hi @Murilo_Livorato

try it:

```auto
GET my-index-000006-test/_search
{
  "runtime_mappings": {
        "month_of_year": {
        "type": "keyword",
         "script": {
        "source": """
        emit(doc['@timestamp'].value.month.getDisplayName(TextStyle.FULL, Locale.ROOT));
        
        """
      }
      }
  },
  "fields" : ["month_of_year"]
}

```

---

<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:** [August 29, 2023, 3:07am UTC](https://discuss.elastic.co/t/runtime-get-month/339721/3 "2023-08-29T03:07:42Z")

</div>

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