# I need to calculate diffrence of the same field with diffrent date but it's not working (elasticsearch , kibana)

**URL:** https://discuss.elastic.co/t/i-need-to-calculate-diffrence-of-the-same-field-with-diffrent-date-but-its-not-working-elasticsearch-kibana/222334
**Category:** Elasticsearch
**Created:** [March 5, 2020, 3:46pm UTC](https://discuss.elastic.co/t/i-need-to-calculate-diffrence-of-the-same-field-with-diffrent-date-but-its-not-working-elasticsearch-kibana/222334 "2020-03-05T15:46:53Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![samargh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samargh/32/70171_2.png) [@samargh](https://discuss.elastic.co/u/samargh)
#### Post date: [March 5, 2020, 3:46pm UTC](https://discuss.elastic.co/t/i-need-to-calculate-diffrence-of-the-same-field-with-diffrent-date-but-its-not-working-elasticsearch-kibana/222334/1 "2020-03-05T15:46:54Z")

</div>

well i have the same field in 2 indexes ,  
i managed to join them in 1 index ,  
but the problem is that i need to calculate the diffrence between activation date in day1 and activation date in day2 (day2 - day 1 shows number of subscribers , but i can't manage to get it )  
i tried this but it's not working  
help  
{  
"query": {  
"function\_score": {  
"query": {  
"match": { "message": "elasticsearch" }  
},  
"script\_score" : {  
"script" : {  
"source": "Math.subtract((day1['Activation Date'].value) , day-2020-01-03['Activation Date'].value)"  
}  
}  
}  
}  
}

* * *

{  
"query": {  
"function\_score": {  
"query": {  
"match": { "message": "elasticsearch" }  
},  
"script\_score" : {  
"script" : {  
"params": {  
"b": "day1['Activation Date'].value",  
"a": "day-2020-01-03['Activation Date'].value"  
},  
"source": "params.a - params.b"  
}  
}  
}  
}  
}

* * *

{  
"query" : {  
"match\_all": {}  
},  
"script\_fields" : {  
"test1" : {  
"script" : {  
"source": "(day-2020-01-03['Activation Date'].value) - (day1['Activation Date'].value)"  
}  
}  
}  
}

* * *

{  
"query": {  
"bool" : {  
"must\_not" : {  
"range" : {  
"Activation Date" : { day-2020-01-03['Activation Date'].value, day1['Activation Date'].value }  
}  
}

---

<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: [April 2, 2020, 3:46pm UTC](https://discuss.elastic.co/t/i-need-to-calculate-diffrence-of-the-same-field-with-diffrent-date-but-its-not-working-elasticsearch-kibana/222334/2 "2020-04-02T15:46:56Z")

</div>

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