# Chnge Datetime format to MMMM yyyy

**URL:** https://discuss.elastic.co/t/chnge-datetime-format-to-mmmm-yyyy/270376
**Category:** Kibana
**Created:** [April 16, 2021, 11:08am UTC](https://discuss.elastic.co/t/chnge-datetime-format-to-mmmm-yyyy/270376 "2021-04-16T11:08:27Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![varunbsgaur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varunbsgaur/32/125005_2.png) [@varunbsgaur](https://discuss.elastic.co/u/varunbsgaur)
#### Post date: [April 16, 2021, 11:08am UTC](https://discuss.elastic.co/t/chnge-datetime-format-to-mmmm-yyyy/270376/1 "2021-04-16T11:08:27Z")

</div>

Hi Team,  
We need to change the format of timestamp to MMMM yyyy . I have tried datetimeformater but it's not working. The result that I got is not aggregated . Kindly help me with this.

my scripted field:-

ZonedDateTime input = doc['timestamp'].value;  
return input;

And have changed format pattern to MMMM YYYY

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

But When i use scripted field in visualization it not attributed. when terms aggregation was used  
please refer screenshots  
my visualization;-

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

Please help me to fix this

---

<div class="post-metadata">

### Author: ![Jason\_Slater](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason_slater/32/63484_2.png) [@Jason\_Slater](https://discuss.elastic.co/u/Jason_Slater)
#### Post date: [April 17, 2021, 8:30am UTC](https://discuss.elastic.co/t/chnge-datetime-format-to-mmmm-yyyy/270376/2 "2021-04-17T08:30:36Z")

</div>

Something like this?

 ![Screen Shot 2021-04-17 at 1.20.40 AM](https://us1.discourse-cdn.com/elastic/original/3X/0/0/00b5aee51c61e9a9d3a4643b84d4c94a31fb12c5.png)

Note that my scripted field is a String, not a Date, which is created from an existing Date field. I'm using the Kibana sample E-Commerce data as a reference. The script is as follows (change order\_date to timestamp in your case).

```
ZonedDateTime input = doc['order_date'].value;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
String output = input.format(formatter);
return output;

```

This is how the data shows up in a Lens visualization, when I drag the scripted field to workspace to use it as the horizontal axis field:

 ![Screen Shot 2021-04-17 at 1.25.09 AM](https://us1.discourse-cdn.com/elastic/original/3X/c/9/c9bfbb372ac3682d7d82d529cd4f55f8860a4226.png)

---

<div class="post-metadata">

### Author: ![Jason\_Slater](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason_slater/32/63484_2.png) [@Jason\_Slater](https://discuss.elastic.co/u/Jason_Slater)
#### Post date: [April 17, 2021, 4:13pm UTC](https://discuss.elastic.co/t/chnge-datetime-format-to-mmmm-yyyy/270376/3 "2021-04-17T16:13:06Z")

</div>

Another idea... truncating the date values in your scripted field

```
ZonedDateTime input = doc['timestamp'].value;
return input.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1);
```

---

<div class="post-metadata">

### Author: ![varunbsgaur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varunbsgaur/32/125005_2.png) [@varunbsgaur](https://discuss.elastic.co/u/varunbsgaur)
#### Post date: [April 19, 2021, 7:07am UTC](https://discuss.elastic.co/t/chnge-datetime-format-to-mmmm-yyyy/270376/4 "2021-04-19T07:07:24Z")

</div>

Thank you soo much Jason Slater for both the replies. They worked like a charm . Appreciate it !!!!

---

<div class="post-metadata">

### Author: ![varunbsgaur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varunbsgaur/32/125005_2.png) [@varunbsgaur](https://discuss.elastic.co/u/varunbsgaur)
#### Post date: [April 20, 2021, 10:16am UTC](https://discuss.elastic.co/t/chnge-datetime-format-to-mmmm-yyyy/270376/5 "2021-04-20T10:16:31Z")

</div>

I have a timestamp value in UTC time zone , within the script is it possible to convert it into local time zone. Then extract year and month from the local timestamp value.

---

<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: [May 18, 2021, 10:17am UTC](https://discuss.elastic.co/t/chnge-datetime-format-to-mmmm-yyyy/270376/6 "2021-05-18T10:17:07Z")

</div>

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