Chnge Datetime format to MMMM yyyy

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

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

Please help me to fix this

Something like this?

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:

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

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

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

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.

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