# Unable to convert DSL argument: Cannot cast java.lang.String to java.util.Date

**URL:** <https://discourse.hibernate.org/t/unable-to-convert-dsl-argument-cannot-cast-java-lang-string-to-java-util-date/6156>\
**Category:** Hibernate Search\
**Created:** [March 17, 2022, 6:14am UTC](https://discourse.hibernate.org/t/unable-to-convert-dsl-argument-cannot-cast-java-lang-string-to-java-util-date/6156 "2022-03-17T06:14:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prashant\_Kamble](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@Prashant\_Kamble](https://discourse.hibernate.org/u/Prashant_Kamble)\
**Post date:** [March 17, 2022, 6:14am UTC](https://discourse.hibernate.org/t/unable-to-convert-dsl-argument-cannot-cast-java-lang-string-to-java-util-date/6156/1 "2022-03-17T06:14:09Z")

</div>

In Hibernate search 5 I was using this code for date filter and it was working fine

```auto
String from = "2022-01-31";
String to ="2022-03-16";
TermRangeQuery.newStringRange(filter.getKey(), from, to, true, true)

```

When migrating it to hibernate search 6 we have converted code like this but it is giving exception

```auto
String from = "2022-01-31";
String to ="2022-03-16";
pf.range().field(filter.getKey()).between(from, to)

```

**Exception**  
` Unable to convert DSL argument: Cannot cast java.lang.String to java.util.Date`

Any reason why we are getting this exception??

---

<div class="post-metadata">

**Author:** ![Prashant\_Kamble](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@Prashant\_Kamble](https://discourse.hibernate.org/u/Prashant_Kamble)\
**Post date:** [March 17, 2022, 10:32am UTC](https://discourse.hibernate.org/t/unable-to-convert-dsl-argument-cannot-cast-java-lang-string-to-java-util-date/6156/2 "2022-03-17T10:32:21Z")

</div>

When we convert string into java.util.Date then it works but we have runtime date format so,How to deal with it?? Also if date has null then??
