Comparing Dates
It is easy to use the compareDate routine, along with a
tJava component to compare two dates, for example, to check if
a date is identical to, earlier than, or later than a specific date, according to the
format specified. This routine takes two parameters (the two dates) and returns one of
the following three values.
- -1: the first date is earlier than the second date.
- 0: the first date is identical to the second date.
- 1: the first date is later than the second date.
The following gives an example of using this routine.
System.out.println(TalendDate.compareDate(TalendDate.parseDate("yyyy-MM-dd", "2015/11/24"), TalendDate.parseDate("yyyy-MM-dd", "2025/11/24")));
This example compares the two dates: 2015/11/24 and 2025/11/24 and returns the value -1 in the Run view, indicating that the first date is earlier than the second date.
![The result is -1 in the Run view.](/en-US/studio-user-guide/8.0-R2024-07/Content/Resources/images/routines14_d.png)