Kibana, getting todays date


(Hüseyin Fatih Akar) #1

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)


(Marius Dragomir) #2

Hello,

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


(Hüseyin Fatih Akar) #3

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?


(Marius Dragomir) #4

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


(Hüseyin Fatih Akar) #5

Yes actually it is.

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


(Marius Dragomir) #6

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


(Hüseyin Fatih Akar) #7

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()


(Marius Dragomir) #8

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


(Hüseyin Fatih Akar) #9

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


(system) #10

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