Compare Date Column Value with Current Date

Introduction

Comparing date values with the current date is a common requirement for many applications. Whether you need to calculate age from a date of birth or determine the time elapsed since a specific date, you can achieve this by using a Bean Shell Formatter in Joget. This technique allows you to perform date calculations and display the results directly in your list columns.

How does it work?

The Bean Shell Formatter allows you to manipulate and format date values within your columns. By using the provided script, you can calculate differences between dates and format the output to display age or elapsed time.

Here’s a sample Bean Shell Formatter script to calculate age from a date of birth:

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();
}
Created by Julieth Last modified by Aadrian on Dec 13, 2024