Comparing Dates - Cloud - 7.3

Talend Studio User Guide

Version
Cloud
7.3
Language
English
Product
Talend Big Data
Talend Big Data Platform
Talend Cloud
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development
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.