Extract 'Year' from 'new Date()' function in Kibana scripted field

How can I extract only year (2020) from new Date() function in Kibana scripted field?
Following is scripted field entry
new Date()
Preview of above function displays
"_id": "a38be692-7b1c-4d9b-a8eb-cfedb15e6937",
"Date test": [
Appreciate your help.

Hello Mike,

You should be able to use new SimpleDateFormat('yyyy') to grab the year. Reference: Scripted fields date parse.


Thanks Aaron. I applied following in scripted field and got current year.
scripted field...
def date = new Date();
def sdf = new SimpleDateFormat('yyyy');
return sdf.format(date);

output ....
[ { "_id": "a38be692-7b1c-4d9b-a8eb-cfedb15e6937", "Date test": [ "2020" ] },

1 Like

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