# Kibana, getting todays date

**URL:** <https://discuss.elastic.co/t/kibana-getting-todays-date/85766>\
**Category:** Kibana\
**Created:** [May 15, 2017, 12:47pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766 "2017-05-15T12:47:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hfakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hfakar/32/18211_2.png) [@hfakar](https://discuss.elastic.co/u/hfakar)\
**Post date:** [May 15, 2017, 12:47pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/1 "2017-05-15T12:47:05Z")

</div>

Hello there,

I want to calculate how many days past with my 'duedate' timestamp.  
I guess I need a scripted field but I cannot get it right. Is there a way to this like  
doc['today'].value - doc['duedate'].value ?  
And it should give 30 (If 30 days passed from the duedate timestamp)

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [May 15, 2017, 6:48pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/2 "2017-05-15T18:48:18Z")

</div>

Hello,

You can use `new Date().getTime()` in scripted fields to get the current timestamp and use that in any operations there.

---

<div class="post-metadata">

**Author:** ![hfakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hfakar/32/18211_2.png) [@hfakar](https://discuss.elastic.co/u/hfakar)\
**Post date:** [May 15, 2017, 7:49pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/3 "2017-05-15T19:49:30Z")

</div>

Thanks for the reply. I did get todays date with your `new Date().getTime()`

But it shows me nothing when I try to get `new Date().getTime() - doc['duedate'].getTime()` and I tried representing it as date, string, number, nothing happens. And it doesnt give any compile or runtime errors?

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [May 15, 2017, 7:52pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/4 "2017-05-15T19:52:18Z")

</div>

Is `duedate` your date field? if so, you should use `doc['duedate'].value`

---

<div class="post-metadata">

**Author:** ![hfakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hfakar/32/18211_2.png) [@hfakar](https://discuss.elastic.co/u/hfakar)\
**Post date:** [May 15, 2017, 7:55pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/5 "2017-05-15T19:55:31Z")

</div>

Yes actually it is. ![](https://us1.discourse-cdn.com/elastic/original/3X/f/3/f36c52eb0108934b49875fd34e2bbaa58a005a3c.png)

So what you are saying is I should try `new Date().getTime() - doc['duedate'].value()` ?

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [May 15, 2017, 7:57pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/6 "2017-05-15T19:57:48Z")

</div>

Yes. I think the getTime returns the date in the same numeric format as the one that's stored on ES.

---

<div class="post-metadata">

**Author:** ![hfakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hfakar/32/18211_2.png) [@hfakar](https://discuss.elastic.co/u/hfakar)\
**Post date:** [May 15, 2017, 8:05pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/7 "2017-05-15T20:05:40Z")

</div>

I tried that and I also did  
`(new Date().getTime()) - doc['duedate'].value()`  
Tried to represent as Number String and date nothing. Both give me 0 results on visualization. But I can get results for `new Date().getTime()`

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [May 15, 2017, 8:15pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/8 "2017-05-15T20:15:08Z")

</div>

I'm sorry, I confirmed your option without checking closely. You should do it without the parenthesis for `value` as that is a property and not a method for that doc type.  
So it should look like this:  
`new Date().getTime() - doc['duedate'].value`  
Also, if you want to get a nice readable output for that field, you should set the Format to `Number`, the Type to `Duration` and the Input Format to `milliseconds`

---

<div class="post-metadata">

**Author:** ![hfakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hfakar/32/18211_2.png) [@hfakar](https://discuss.elastic.co/u/hfakar)\
**Post date:** [May 15, 2017, 8:26pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/9 "2017-05-15T20:26:18Z")

</div>

Perfect! Thank you ! Now everything looks perfect! Thanks for your time really.

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

---

<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:** [June 12, 2017, 8:39pm UTC](https://discuss.elastic.co/t/kibana-getting-todays-date/85766/10 "2017-06-12T20:39:33Z")

</div>

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