# Want to format date

**URL:** https://discuss.elastic.co/t/want-to-format-date/234312
**Category:** Kibana
**Tags:** painless
**Created:** [May 26, 2020, 10:54am UTC](https://discuss.elastic.co/t/want-to-format-date/234312 "2020-05-26T10:54:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![shubhamblackstratus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubhamblackstratus/32/60703_2.png) [@shubhamblackstratus](https://discuss.elastic.co/u/shubhamblackstratus)
#### Post date: [May 26, 2020, 10:54am UTC](https://discuss.elastic.co/t/want-to-format-date/234312/1 "2020-05-26T10:54:03Z")

</div>

My current date format is "2019-11-11T05:59:12.000Z" and I want to modify this with day\_of\_the\_week. I tried to achieve it by utilising painless script but it forces me to use terms as an aggregation without mentioning date.

I need date format should be changed to this format as Mon 2019-11-11T05:59:12.000Z. I also tried painless script examples from Elasticsearch documentation but always I started and ended up with following error as "Cannot cast org.elasticsearch.script.JodaCompatibleZonedDateTime to java.time.ZonedDateTime"

I used following script copied from documentation.

```auto
ZonedDateTime input = doc['order.date'].value;
String output = input.format(DateTimeFormatter.ISO_INSTANT);

```

I had also tried to add two fields to construct my own format as shown below but I got an error as  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/a/6ac2c647c800912c8920f74cbcc2ce27cdda56e8.png)

```auto
["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][doc['order.date'].value.dayOfWeek] + [doc['order.date'].value]

```

please help to achive this.

---

<div class="post-metadata">

### Author: ![Dzmitry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dzmitry/32/65026_2.png) [@Dzmitry](https://discuss.elastic.co/u/Dzmitry)
#### Post date: [May 26, 2020, 3:13pm UTC](https://discuss.elastic.co/t/want-to-format-date/234312/2 "2020-05-26T15:13:05Z")

</div>

Hi @shubhamblackstratus,

You should be able to achieve it by updating field type to `date` and adding `dddd` to the format pattern:

 ![order_date - kibana_sample_data_ecommerce - Elastic 2020-05-26 17-10-17](https://us1.discourse-cdn.com/elastic/original/3X/2/6/268a494f6c791cfd08132362b01a9488b5464222.png)

update: for the shorter names (Mon, Tue, etc) use `ddd`

Regards, Dzmitry

---

<div class="post-metadata">

### Author: ![shubhamblackstratus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubhamblackstratus/32/60703_2.png) [@shubhamblackstratus](https://discuss.elastic.co/u/shubhamblackstratus)
#### Post date: [May 27, 2020, 4:35am UTC](https://discuss.elastic.co/t/want-to-format-date/234312/3 "2020-05-27T04:35:07Z")

</div>

Thank you @Dzmitry for your suggestion.

I could do this only if its related to timestamp.

I want to create scripted field by using indexed document key field named as _ **order.date** _ which is mapped as "date" datatype.

Please suggest.

---

<div class="post-metadata">

### Author: ![shubhamblackstratus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubhamblackstratus/32/60703_2.png) [@shubhamblackstratus](https://discuss.elastic.co/u/shubhamblackstratus)
#### Post date: [June 2, 2020, 5:26am UTC](https://discuss.elastic.co/t/want-to-format-date/234312/4 "2020-06-02T05:26:33Z")

</div>

@magnusbaeck @Dzmitry please help..!

---

<div class="post-metadata">

### Author: ![shubhamblackstratus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubhamblackstratus/32/60703_2.png) [@shubhamblackstratus](https://discuss.elastic.co/u/shubhamblackstratus)
#### Post date: [June 26, 2020, 8:29am UTC](https://discuss.elastic.co/t/want-to-format-date/234312/5 "2020-06-26T08:29:11Z")

</div>

Guys any hep over here ?

---

<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: [July 24, 2020, 8:29am UTC](https://discuss.elastic.co/t/want-to-format-date/234312/6 "2020-07-24T08:29:30Z")

</div>

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