Looking for a way to calculate time lapse in openrefine

692 views Asked by At

This is the given expression of GREL language on OpenRefine.

diff(date d1, date d2, optional string timeUnit)

For dates, returns the difference in given time units.

So the question is how to get the access to the values of both columns, that is not clear on presented on the documentation.

Thanks

2

There are 2 answers

0
Ettore Rizza On BEST ANSWER

The formula for accessing another column is:

cells.YourColumnName.value

If your column name contains spaces or non-ascii characters :

cells['Your Column Name'].value

So, assuming your two columns are named "date1" and "date2", and you want the difference in days, the GREL formula is as follows :

diff(cells.date1.value, cells.date2.value, "days")

or

diff(cells['date1'].value, cells['date2'].value, "days")
2
Joni Hoppen On

I found a way myself here is the example of the working command, the GREL documentation is not that explicit treating this procedure.

Here is the commend I used, I multiplied the result by -1 to make it positive.

diff(cells["DATA_COMPRA"].value, cells["DATA_VENCIMENTO"].value, "days") * -1

Hope that helps, I my have to come back here sometimes to get this script again and again.