Skip to end of metadata
Go to start of metadata

Let's say that you have such use cases:

  • Calculate a person's age based on a column that stores the person's date of birth
  • Compare a date with the current date to calculate how long it has elapsed since
  • etc.

To fulfill this case, you can simply use a Bean Shell Formatter on a column with date values to perform the calculation with this script below:

import java.text.ParseException;
import java.time.LocalDate;
import java.time.Period;

try {
    LocalDate birthDate = LocalDate.parse(value);
    LocalDate currentDate = LocalDate.now();
    
    Period dateDiff = Period.between(birthDate, currentDate);
    
    return dateDiff.getYears() + " YEAR(s) & " + dateDiff.getMonths() + " MONTH(s)";
} catch (ParseException e) {
    e.printStackTrace();
}




  • No labels