English |
---|
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.
...
Code Block | ||
---|---|---|
| ||
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(); } |
To quickly see how this script works, feel free to try this sample app below:
...