Expression Language - DateDiff function

I’ve seen the post where the days between two dates can be calculated by converting the two dates to milliseconds past the Unix epoch, subtracting them, and then converting the result to the desired unit of time. Please add a DateDiff function to the Expression Language that would take two Joda DateTime objects as input and calculate the difference based on the user supplied time unit.

DateDiff (Joda DateTime 1, Joda DateTime 2, unit)

where unit could be milliseconds, seconds, minutes, hours, days, months, years.

I would say this is something that can be done with an Expression Library and not necessarily something that needs to be supported natively in the language. I’ve written a prototype that is modeled after the Java TimeUnit and ChronoUnit interfaces. You can take a look here:

To use it in a pipeline, import the library into the pipeline and then you can reference it like so:

lib.datetime.ChronoUnit.YEARS.between($date1, $date2)

That would compute the number of years between the two dates. Let me know if something like this works for you.

I’m attaching an example pipeline that you can play with here:

DateTimeLibDemo_2018_06_11.slp (4.2 KB)

Note: This pipeline imports the file from GitHub, but I don’t think that will be cached at the moment. So, it would be better to copy it into SLFS and import it from there.