# Painless script for date to minutes calculation

**URL:** https://discuss.elastic.co/t/painless-script-for-date-to-minutes-calculation/243252
**Category:** Kibana
**Created:** [July 30, 2020, 4:15pm UTC](https://discuss.elastic.co/t/painless-script-for-date-to-minutes-calculation/243252 "2020-07-30T16:15:25Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)
#### Post date: [August 4, 2020, 8:00am UTC](https://discuss.elastic.co/t/painless-script-for-date-to-minutes-calculation/243252/8 "2020-08-04T08:00:38Z")

</div>

If it doesn't change, why no calculating the value in log stash and storing it in a numeric field in Elasticsearch? this is the best option in this case. You can do this with a ruby filter in Logstash, here's an example that's a similar use case:

> [@Get Difference between two date field with ruby filter](https://discuss.elastic.co/t/get-difference-between-two-date-field-with-ruby-filter/97100):
>
> Hi All I have been trying the ruby code to get the difference between 2 dates Start Date : 2017-06-13T01:17:07.000Z End Date : 2017-07-13T01:17:10.000Z I need difference between these 2 dates. I have dried this but i get ruby exception error ruby { init =\> "require 'time'" code =\> " start = Time.iso8601(event['Start Date'].to\_s).to\_i; end = Time.iso8601(event['End Date'].to\_s).to\_i; event['timediff'] = start - end; " add\_tag =\> [ "calculat…

Best,  
Matthias

---

_[View the full topic](https://discuss.elastic.co/t/painless-script-for-date-to-minutes-calculation/243252)._
