# Empty Values in DateTimeStamp - Ignore Empty Values & Perform Calculation

**URL:** <https://discuss.elastic.co/t/empty-values-in-datetimestamp-ignore-empty-values-perform-calculation/267721>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [March 18, 2021, 9:25pm UTC](https://discuss.elastic.co/t/empty-values-in-datetimestamp-ignore-empty-values-perform-calculation/267721 "2021-03-18T21:25:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![prohit](https://avatars.discourse-cdn.com/v4/letter/p/b487fb/32.png) [@prohit](https://discuss.elastic.co/u/prohit)\
**Post date:** [March 18, 2021, 9:25pm UTC](https://discuss.elastic.co/t/empty-values-in-datetimestamp-ignore-empty-values-perform-calculation/267721/1 "2021-03-18T21:25:55Z")

</div>

Hi All,

Ver: 7.11 (Painless script)

1. I have datetimestamp fields in number type, to convert into date format i have used doc['actualdatetimestamp'].value with the default format in painless script it worked

Need Help in Two Questions Please:

1. Now i want to subtract two fields doc['targetdatetimestamp'].value - doc['actualdatetimestamp'].value, it is giving me errors because of some the documents are blank in doc['actualdatetimestamp'].value, how to ignore blank and proceed to calculation

2. Now a product is been developed and deployed in production,  
-i need to find out if the product is deployed on or before the doc['expecteddate'] against doc['actualdate'],  
Case1: if it is deployed on/before doc['expecteddate'] than it will be 100%,  
Case2: If it is deployed 1 day after doc['expecteddate'] than it will be 80%

Kindly provide your valuable suggestion, your suggestions would really help me since i am beginner in KIBANA.

Stay Safe !

Regards,  
PR

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [March 18, 2021, 11:45pm UTC](https://discuss.elastic.co/t/empty-values-in-datetimestamp-ignore-empty-values-perform-calculation/267721/2 "2021-03-18T23:45:51Z")

</div>

1. 

Use an if statement.  
if there is no value, calculate with 0.

1. 

Use an if statement.  
if the difference is zero/negative, return 80%. else return 100%

---

<div class="post-metadata">

**Author:** ![prohit](https://avatars.discourse-cdn.com/v4/letter/p/b487fb/32.png) [@prohit](https://discuss.elastic.co/u/prohit)\
**Post date:** [March 19, 2021, 9:39pm UTC](https://discuss.elastic.co/t/empty-values-in-datetimestamp-ignore-empty-values-perform-calculation/267721/3 "2021-03-19T21:39:14Z")

</div>

Hi Clerk,

Kindly correct me if the below script is right? this is my first script not sure if it's works, please help me here, much appreciate your time here.

1. 

doc['targetdatetimestamp'].value - doc['actualdatetimestamp'].value  
if (doc['actualdatetimestamp']).empty {  
return "0";  
}

1. 

if doc['expecteddate'].value - doc['actualdate'].value \<0 {  
return "80%";  
} else if doc['expecteddate'].value - doc['actualdate'].value \>= 0 {  
return "100%";  
}

80/100 % should be number type

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [March 22, 2021, 3:12am UTC](https://discuss.elastic.co/t/empty-values-in-datetimestamp-ignore-empty-values-perform-calculation/267721/4 "2021-03-22T03:12:52Z")

</div>

Looks OK.  
Just check if the document is empty as the first condition.

---

<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 19, 2021, 3:13am UTC](https://discuss.elastic.co/t/empty-values-in-datetimestamp-ignore-empty-values-perform-calculation/267721/5 "2021-04-19T03:13:23Z")

</div>

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