# Sum of miliseconds Kibana

**URL:** <https://discuss.elastic.co/t/sum-of-miliseconds-kibana/236790>\
**Category:** Kibana\
**Created:** [June 11, 2020, 9:53pm UTC](https://discuss.elastic.co/t/sum-of-miliseconds-kibana/236790 "2020-06-11T21:53:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gribeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gribeiro/32/70195_2.png) [@gribeiro](https://discuss.elastic.co/u/gribeiro)\
**Post date:** [June 11, 2020, 9:53pm UTC](https://discuss.elastic.co/t/sum-of-miliseconds-kibana/236790/1 "2020-06-11T21:53:55Z")

</div>

Hi,

I have in my SQL Server a DateTime2 Field which represents how long a task took to be completed.  
In a simple way, the value is `StartDateTimeOfTask - GetDate()`, that gives me the result in seconds, and it would be stored like this: 1900-01-01 00:00:05.0966667 --\> the task took 5 seconds to complete.

![image](https://us1.discourse-cdn.com/elastic/original/3X/3/9/391213de45a498f82b967a407e7798801ce7335c.png)

I've tried to store in my ES 7.7 this data ( as DateTime or Integer) so I could sum the time by task, tried to format as Duration and Number 00:00:00, but without success

I've found this topic [JSON Input: Converting Minutes to Minutes and Seconds](https://discuss.elastic.co/t/json-input-converting-minutes-to-minutes-and-seconds/100845) which almost get what I want, but the result is not what I was expecting:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/d/dd7ca549c86a07e5c5930fab60e9faac70e05e95.png)

So what I am trying to do is to insert this kind of data in a certain way that I will be able to Sum the seconds/miliseconds of a group of tasks

is this possible in anyway?

Thank you very much,  
G

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [June 12, 2020, 3:03pm UTC](https://discuss.elastic.co/t/sum-of-miliseconds-kibana/236790/2 "2020-06-12T15:03:26Z")

</div>

I don't know how SQL Server work but I can't understand why `StartDateTimeOfTask - GetDate()` will give you back a date instead of the difference in millis between the end date and the start date.  
Having this as a simple integer it will be much easier to store in ES and do all the calculations you need.  
Could you try to convert `StartDateTimeOfTask` and `GetDate()` to UTCmillis?  
Is something like this available in SQL Server: `DATEDIFF(MILLISECOND, begin, end)`? this should return an integer value of milliseconds elapsed from the begin to the end

---

<div class="post-metadata">

**Author:** ![gribeiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gribeiro/32/70195_2.png) [@gribeiro](https://discuss.elastic.co/u/gribeiro)\
**Post date:** [June 14, 2020, 3:06pm UTC](https://discuss.elastic.co/t/sum-of-miliseconds-kibana/236790/3 "2020-06-14T15:06:51Z")

</div>

I created another column in MSSQL Table, saving the milliseconds as Integer, using `DATEDIFF`, and when sending it to ESK is working as expected.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/5/a50e734a9660dd483d7ed6e560919c334edb9aa5.png)

So, in order to display in a more readable way, I created a scripted field, to display minutes:seconds.milliseconds

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/5/25a73dad5d96b1385cf6f1e5cbe8525564f719bd.png)

For the purpose of displaying document per document, it works perfectly, but I cannot Sum this scripted field, because is now a date type. Is there a way to create a sum to visualize this number as hh:mm:ss.SSSS?  
Otherwise I have the sum of thousands of milliseconds, like this:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/e/eeae65fa1d2973d8f863b01566e9a7c3007e6871.png)  
this sum represents 1 minutes - 6 seconds - 814 milliseconds

Thanks

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [June 14, 2020, 5:41pm UTC](https://discuss.elastic.co/t/sum-of-miliseconds-kibana/236790/4 "2020-06-14T17:41:48Z")

</div>

Hi, you don't need to use a scripted field for that, you can just specify the format as `Number` and use the following `NumberJS` to format as time `00:00:00`  
This will keep your field as number to allow all the numeric aggregation you need, but you are then formatting the number as a time

 ![Screenshot 2020-06-14 at 19.41.55](https://us1.discourse-cdn.com/elastic/original/3X/d/0/d0507ab88e18a90e9e06ef7e623ed2a1bb43d2fb.png)

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [June 14, 2020, 5:43pm UTC](https://discuss.elastic.co/t/sum-of-miliseconds-kibana/236790/5 "2020-06-14T17:43:49Z")

</div>

This unfortunately only play nicely with seconds

---

<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 12, 2020, 5:43pm UTC](https://discuss.elastic.co/t/sum-of-miliseconds-kibana/236790/6 "2020-07-12T17:43:53Z")

</div>

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