# Invalid format: "2014-05-27T00:00:00.000Z" is malformed at "T00:00:00.000Z"

**URL:** <https://discuss.elastic.co/t/invalid-format-2014-05-27t00-00-00-000z-is-malformed-at-t00-00-00-000z/43070>\
**Category:** Elasticsearch\
**Created:** [March 1, 2016, 5:10am UTC](https://discuss.elastic.co/t/invalid-format-2014-05-27t00-00-00-000z-is-malformed-at-t00-00-00-000z/43070 "2016-03-01T05:10:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![moni15moni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moni15moni/32/42311_2.png) [@moni15moni](https://discuss.elastic.co/u/moni15moni)\
**Post date:** [March 1, 2016, 5:10am UTC](https://discuss.elastic.co/t/invalid-format-2014-05-27t00-00-00-000z-is-malformed-at-t00-00-00-000z/43070/1 "2016-03-01T05:10:29Z")

</div>

The following exception i am gettting with the below code snippet.The time which i have based is date object.but the milliseconds added default in the query.how can i overridden by java API.I am using 2.1 elasticsearch Version

RangeQueryBuilder dateRangeFilter = QueryBuilders.rangeQuery("first\_occurance").timeZone("yyyy-MM-dd HH:mm:ss");  
dateRangeFilter.gte(to.getTime());  
dateRangeFilter.gte(from.getTime());

java.lang.IllegalArgumentException: Invalid format: "2014-05-27T00:00:00.000Z" is malformed at "T00:00:00.000Z"

Thanks  
Moni

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [March 1, 2016, 7:49am UTC](https://discuss.elastic.co/t/invalid-format-2014-05-27t00-00-00-000z-is-malformed-at-t00-00-00-000z/43070/2 "2016-03-01T07:49:49Z")

</div>

I think you mix a few things up. First of all, you provide a date format to the `timeZone()` method which produces yet another exception. Next, you are calling the `getTime()` on a date, which just outputs a numeric timestamp in milliseconds since epoch. I assume you previously just provided the `Date` object directly, which prints itself in ISO-8601 timestamp (which you see in your error message). In addition, you call the `gte()` method twice. I assume you want to call `gte()` for the `from` date and `lte()` for the `to` date.

This fully working example should get you started:

```auto
String format = "yyyy-MM-dd HH:mm:ss";

SimpleDateFormat df = new SimpleDateFormat(format);
// just create some random dates for this example...
Date from = df.parse("2014-01-01 10:05:12");
Date to = df.parse("2016-02-01 11:03:23");

RangeQueryBuilder dateRangeFilter = QueryBuilders
    .rangeQuery("first_occurance")
    .format("yyyy-MM-dd HH:mm:ss");
dateRangeFilter.gte(df.format(from));
dateRangeFilter.lte(df.format(to));

System.out.println(dateRangeFilter.toString());

```

This prints:

```auto
{
  "range" : {
    "first_occurance" : {
      "from" : "2014-01-01 10:05:12",
      "to" : "2016-02-01 11:03:23",
      "include_lower" : true,
      "include_upper" : true,
      "format" : "yyyy-MM-dd HH:mm:ss",
      "boost" : 1.0
    }
  }
}

```

Daniel

---

<div class="post-metadata">

**Author:** ![moni15moni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moni15moni/32/42311_2.png) [@moni15moni](https://discuss.elastic.co/u/moni15moni)\
**Post date:** [March 2, 2016, 6:27am UTC](https://discuss.elastic.co/t/invalid-format-2014-05-27t00-00-00-000z-is-malformed-at-t00-00-00-000z/43070/3 "2016-03-02T06:27:04Z")

</div>

Thanks for a quick response Daniel,It's Working fine.You are awesome.

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [March 2, 2016, 2:04pm UTC](https://discuss.elastic.co/t/invalid-format-2014-05-27t00-00-00-000z-is-malformed-at-t00-00-00-000z/43070/4 "2016-03-02T14:04:30Z")

</div>

You're welcome. Glad I could help and your problem is now solved. 🙂

---

<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 5, 2017, 11:12pm UTC](https://discuss.elastic.co/t/invalid-format-2014-05-27t00-00-00-000z-is-malformed-at-t00-00-00-000z/43070/5 "2017-07-05T23:12:01Z")

</div>


