# Painless compare string dates

**URL:** <https://discuss.elastic.co/t/painless-compare-string-dates/101230>\
**Category:** Elasticsearch\
**Created:** [September 20, 2017, 8:17pm UTC](https://discuss.elastic.co/t/painless-compare-string-dates/101230 "2017-09-20T20:17:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Vaisberg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_vaisberg/32/22337_2.png) [@Alex\_Vaisberg](https://discuss.elastic.co/u/Alex_Vaisberg)\
**Post date:** [September 20, 2017, 8:17pm UTC](https://discuss.elastic.co/t/painless-compare-string-dates/101230/1 "2017-09-20T20:17:36Z")

</div>

Hi,

I need compare two dates in painless script inline to update documents. I try in Kibana Console:

```
GET indexName/Type/1111/_update
{
  "script":{
    "lang": "painless",
    "inline": "ctx._source.accounts.removeIf(i -> i.accountId == params.newobject.accountId && i.expirationDate < params.newobject.expirationDate);
ctx._source.accountsVisibility.add(params.newobject);",
    "params": {
      "newobject":{
        "accountId": 3,
        "expirationDate": "2017-09-18T18:42:39.965Z"
       }
    }
  }
}

```

But i get error

> class\_cast\_exception: Cannot apply [\<] operation to types [java.lang.String] and [java.lang.String]

How I convert the string to date for compare in script?

Thanks.

---

<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:** [October 18, 2017, 8:17pm UTC](https://discuss.elastic.co/t/painless-compare-string-dates/101230/2 "2017-10-18T20:17:51Z")

</div>

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