Calculate Difference between 2 Dates in Scipted Field

Hi ,
i try to create a new scripted field by calculating the difference(in minitues) between 2 dates in the following format :
bookingStatus.confirmed :Jan 22, 2020 @ 12:20:00.000
bookingStatus.wating :Jan 20, 2020 @ 10:20:00.000

i like the result be like : Xdays ,Xhours, Xminutes
in this case duration = 2 days , 2 hours ,0minutes

i try this expression but i don't get the correct result:

doc['bookingStatus.confirmed'].value.getMillis() - doc['bookingStatus.wating'].value.getMillis()

C2

any help please !

In your example, you have the following dates:

bookingStatus.confirmed :Jan 22, 2020 @ 12:20:00.000
bookingStatus.wating :Jan 20, 2020 @ 10:20:00.000

The difference between those is roughly two days (20th of January to 22nd of January) - the "human readable" format will do some rounding to get a nice representation. It's currently not possible to get an exact duration in a human readable form, to replicate something like this you could try to implement it yourself in the scripted field and return a string instead.

Hi @flash1293 ,

i try with the to methodes:

it's possible to display "statusDate" ( scriptedfield :String ) in a visualization ( X-axe) ?

It's possible to use the scripted field on an x axis, but not as a histogram, but as an ordinal "terms" scale. So the distance between two statusDates on the axis won't be in scale with the duration

can you give me an example please !

  • Go to Visualize
  • Click Create new Visualization
  • Select bar chart
  • Add bucket
  • Select "Terms" aggregation
  • Select "statusDate" field
  • Apply

I made an error in the first response , i want to display it in (Y-axis)

That's not possible with a string field, you will need to use your original number scripted field with a duration field formatter. The exact value you unfortunately can't show this way.

okey ,
thank you for reply

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