# Painless String to Date

**URL:** <https://discuss.elastic.co/t/painless-string-to-date/87993>\
**Category:** Elasticsearch\
**Created:** [June 1, 2017, 9:57pm UTC](https://discuss.elastic.co/t/painless-string-to-date/87993 "2017-06-01T21:57:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [June 1, 2017, 9:57pm UTC](https://discuss.elastic.co/t/painless-string-to-date/87993/1 "2017-06-01T21:57:24Z")

</div>

Hi,

Trying to convert String to Date in Painless

Painless Code:

`LocalDateTime.parse(item.to_as_string, DateTimeFormatter.ISO_DATE)`

Resulting in following error:

`ScriptException[runtime error]; nested: DateTimeParseException[Text '2017-06-01' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2017-06-01 of type java.time.format.Parsed]; nested: DateTimeException[Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2017-06-01 of type java.time.format.Parsed]; nested: DateTimeException[Unable to obtain LocalTime from TemporalAccessor: {},ISO resolved to 2017-06-01 of type java.time.format.Parsed]; "`

[ISO\_DATE](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE) supports 'yyyy-MM-dd' format.

If this way of converting string to date doesn't work, is there any other simple way?

Any help appreciated !!

---

<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:** [June 29, 2017, 9:57pm UTC](https://discuss.elastic.co/t/painless-string-to-date/87993/2 "2017-06-29T21:57:44Z")

</div>

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