# date.toString() doesn't work after upgrading to ES 8.3

**URL:** <https://discuss.elastic.co/t/date-tostring-doesnt-work-after-upgrading-to-es-8-3/311290>\
**Category:** Elasticsearch\
**Tags:** runtime-fields\
**Created:** [August 3, 2022, 10:22am UTC](https://discuss.elastic.co/t/date-tostring-doesnt-work-after-upgrading-to-es-8-3/311290 "2022-08-03T10:22:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joao\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joao_silva/32/100378_2.png) [@Joao\_Silva](https://discuss.elastic.co/u/Joao_Silva)\
**Post date:** [August 3, 2022, 10:22am UTC](https://discuss.elastic.co/t/date-tostring-doesnt-work-after-upgrading-to-es-8-3/311290/1 "2022-08-03T10:22:12Z")

</div>

After updating the ES to the newest version some of my runtime fields stop working, basically, the date.toString() doesn't work anymore to convert a date to a string.

Is there any option for this? I have been searching for hours in the release notes and I couldn't find anything regarding this.

This is my code:

```auto
{
 "runtime": {
   "dateAsString": {
     "type": "keyword",
     "script": """if (doc['date'].empty) {
     					emit('');
     				} else {
                emit(doc['date'].value.toString('dd-MM-yyyy')); // this field is broken
              }"""
   },
   "milage": {
     "type": "keyword",
     "script": """if (doc['end.odometer'].empty) {
     					emit('-');
     				} else {
                emit(doc['end.odometer'].value.toString()); // this one works perfectly
              }"""
   }
 }
}

```

The dashboards and indexes using the field `dateAsString` are all broken, by doing some debug I kno for a fact that `.toString()` works for the `milage` field.

---

<div class="post-metadata">

**Author:** ![Joao\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joao_silva/32/100378_2.png) [@Joao\_Silva](https://discuss.elastic.co/u/Joao_Silva)\
**Post date:** [August 3, 2022, 10:50am UTC](https://discuss.elastic.co/t/date-tostring-doesnt-work-after-upgrading-to-es-8-3/311290/2 "2022-08-03T10:50:55Z")

</div>

Finally got it working, if anyone else got the same issue, this is how I solved it:

```auto
"script": """if (doc['date'].empty) {
     					emit('');
     				} else {
     				    DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
                        DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
                        Date date = inputFormat.parse(doc['date'].value.toString());
                        emit(formatter.format(date));
              }"""
   },

```

---

<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 31, 2022, 10:51am UTC](https://discuss.elastic.co/t/date-tostring-doesnt-work-after-upgrading-to-es-8-3/311290/3 "2022-08-31T10:51:26Z")

</div>

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