# Groovy to painless

**URL:** <https://discuss.elastic.co/t/groovy-to-painless/75503>\
**Category:** Elasticsearch\
**Created:** [February 17, 2017, 1:54pm UTC](https://discuss.elastic.co/t/groovy-to-painless/75503 "2017-02-17T13:54:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![living\_jordi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/living_jordi/32/61363_2.png) [@living\_jordi](https://discuss.elastic.co/u/living_jordi)\
**Post date:** [February 17, 2017, 1:54pm UTC](https://discuss.elastic.co/t/groovy-to-painless/75503/1 "2017-02-17T13:54:37Z")

</div>

I'm strugling with this compilation code:

```
[esn1] failed to load/compile script [day]: {
  "type" : "script_exception",
   "reason" : "compile error",
   "caused_by" : {
     "type" : "illegal_argument_exception",
     "reason" : "invalid sequence of tokens near ['DateTime'].",
     "caused_by" : {
       "type" : "no_viable_alt_exception",
       "reason" : null
     }
   },
   "script_stack" : [
     "def opDate = new DateTime(doc[params.field ...",
     " ^---- HERE"
   ],
   "script" : "def opDate = new DateTime(doc[params.field].date);opDate.getDayOfMonth();",
   "lang" : "painless"
 }

```

I'm trying to translate a groovy script to painless script. I'm trying to get `day of a month` of a date.

My groovy script is:

```
def opDate = new DateTime(doc[params.field].date);opDate.getDayOfMonth();

```

How could I "translate" it?

Thanks.

---

<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:** [February 17, 2017, 2:38pm UTC](https://discuss.elastic.co/t/groovy-to-painless/75503/2 "2017-02-17T14:38:51Z")

</div>

Hi @living_jordi,

can you try this?

```auto
Instant.ofEpochMilli(doc['field'].value).atZone(ZoneId.systemDefault()).getDayOfMonth()

```

Daniel

---

<div class="post-metadata">

**Author:** ![living\_jordi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/living_jordi/32/61363_2.png) [@living\_jordi](https://discuss.elastic.co/u/living_jordi)\
**Post date:** [February 20, 2017, 7:21am UTC](https://discuss.elastic.co/t/groovy-to-painless/75503/3 "2017-02-20T07:21:31Z")

</div>

Hi @danielmitterdorfer,

Thanks for your answer. It looks like well.

---

<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:** [March 20, 2017, 7:21am UTC](https://discuss.elastic.co/t/groovy-to-painless/75503/4 "2017-03-20T07:21:44Z")

</div>

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