Number of Days between date Range


I have a date Range. Lets say 2015-01-01 to 2017-03-01.

I wanted to calculate only days between this two dates using scripted field.

How can i achieve this ?

Hi, lets say you have two fields in each of your documents, start and end that correspond to the 2015-01-01 and 2017-03-01 dates in your example, respectively.

Then you can create a new scripted field with this script (language = Painless):

(doc['end'].value.getMillis() - doc['start'].value.getMillis()) / 1000 / 60 / 60 / 24
1 Like

Thanks @shaunak.

I tried this but got the following run time error. I am a real newbie to this, but what could be wrong?

reason":"runtime error","caused_by":{"type":"illegal_argument_exception","reason":"Unable to find dynamic method [getMillis] with [0] arguments for class [java.lang.Long]."},"script_stack":["return (doc['Completeness Review Date Time Submitted'].value.getMillis() - doc['Completeness Review Date Time Submitted'].value.getMillis()) / 1000 / 60 / 60 / 24

@lisafitzsimons I think this is because syntax what you have written is not correct.

You can just put (doc['Completeness Review Date Time Submitted']) in scripted field and see whether you are getting value or not.

Or you can try this

doc['Completeness Review Date Time Submitted].value/(2460601000) - doc['Completeness Review Date Time Submitted'].value/(2460601000)