Problems with date subtraction

(Mickael Fraga) #1

Good morning, I would like help.

My problem is this, I need to create a field in kibana which is the subtraction of two date fields ex (2017-01-01 - 2017-01-11) where the result would be 10 days

I'm creating a painless doc ['date1']. Value - doc ['date2']. Value is not working
help me

(Lee Drengenberg) #2

Are your field strings or date types?

You can look at the index pattern to see. For example my date1 and date2 are dates (they're also scriptable and aggregatable which I think they need to be if you use them in a scripted field);

Then I created this scripted field (the difference in dates is in milliseconds so I divide by 1000 to get seconds, by 60 to get minutes, by 60 to get hours, by 24 to get days);
(doc['date2'].value - doc['date1'].value) / 1000 / 60/ 60 /24

And the result is 10;

If you'r dates are strings, I'll have to find the trick to convert them and then I expect it would be the same formula.


(system) #3

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