# How can I do date-calculation/conversion in an MVEL script in ES 1.0.0?

**URL:** <https://discuss.elastic.co/t/how-can-i-do-date-calculation-conversion-in-an-mvel-script-in-es-1-0-0/16010>\
**Category:** Elasticsearch\
**Created:** [February 25, 2014, 1:49pm UTC](https://discuss.elastic.co/t/how-can-i-do-date-calculation-conversion-in-an-mvel-script-in-es-1-0-0/16010 "2014-02-25T13:49:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![h\_b\_wassenaar](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@h\_b\_wassenaar](https://discuss.elastic.co/u/h_b_wassenaar)\
**Post date:** [February 25, 2014, 1:49pm UTC](https://discuss.elastic.co/t/how-can-i-do-date-calculation-conversion-in-an-mvel-script-in-es-1-0-0/16010/1 "2014-02-25T13:49:21Z")

</div>

Hello,

I'm considering upgrading from 0.90.3 to 1.0.0, but I've hit a snag with  
one of the MVEL scripts I use to update documents through the update api.  
My update-script uses Joda to parse/format/manipulate dates, but it appears  
that Joda is no longer available to MVEL scripts in version 1.0.0. (I think  
it changed in commit c7f6c52 from november 24th, so it's been like that for  
a while)

Here are some code-snippets of how it currently works

parser = Joda.forPattern('dateOptionalTime').parser();  
lastdate = parser.parseMillis(update.date);  
prevdate = parser.parseMillis(ctx.\_source.published);  
timediff = lastdate-prevdate;  
...  
nextdate=parser.parseMutableDateTime(update.date);  
nextdate.addHours(calculated\_hours);  
ctx.\_source.nextupdate =  
nextdate.toString('YYYY-MM-dd'T'HH:mm:ss'Z'');

Is there some way to do similar date/time calculations in ES 1.0.0?

I've considered I could use a native script to do these updates; however,  
when I wrote the update-script I tested this, and to my surprise using a  
native script proved to be significantly slower than using the MVEL script  
for this use-case.

Any help would be much appreciated,  
-- Harmen

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a263df38-557e-4221-9b71-19ba78737edf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a263df38-557e-4221-9b71-19ba78737edf%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 1:47am UTC](https://discuss.elastic.co/t/how-can-i-do-date-calculation-conversion-in-an-mvel-script-in-es-1-0-0/16010/2 "2017-07-06T01:47:26Z")

</div>

Closed on July 6, 2017, 1:47am UTC


