Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I need to know if the time of an existing date format (example 2022-07-28 02:32:00) is between 00:00:00 and 05:15:00.
I don't know how to do in TMAP, someone could help me ?
@M CANTAL , no a function we can use directly to compare the time of a date if it is between a time range, here I create a function in a user routine to do it.
package routines;
import java.util.Calendar;
import java.util.Date;
public class MyRoutine {
public static boolean compareTime(Date param1) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(param1);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
Date startDate=TalendDate.parseDate("HH:mm:ss","00:00:00");
Date endDate=TalendDate.parseDate("HH:mm:ss","05:15:00");
Date inputDate=TalendDate.parseDate("HH:mm:ss",""+hour+":"+minute+":"+second);
if(TalendDate.compareDate(inputDate, startDate)!=-1&&TalendDate.compareDate(inputDate, endDate)!=1){
return true;
}else {
return false;
}
}
}
This function requires an input parameter with Date type and it returns a booelan value (true or false);
Then, we can call this function on tMap, here is an example.
Hope it helps you!
Regards
Shong
Only the time part needs to be compared, not the date part?
Yes, only the time part
@M CANTAL , no a function we can use directly to compare the time of a date if it is between a time range, here I create a function in a user routine to do it.
package routines;
import java.util.Calendar;
import java.util.Date;
public class MyRoutine {
public static boolean compareTime(Date param1) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(param1);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
Date startDate=TalendDate.parseDate("HH:mm:ss","00:00:00");
Date endDate=TalendDate.parseDate("HH:mm:ss","05:15:00");
Date inputDate=TalendDate.parseDate("HH:mm:ss",""+hour+":"+minute+":"+second);
if(TalendDate.compareDate(inputDate, startDate)!=-1&&TalendDate.compareDate(inputDate, endDate)!=1){
return true;
}else {
return false;
}
}
}
This function requires an input parameter with Date type and it returns a booelan value (true or false);
Then, we can call this function on tMap, here is an example.
Hope it helps you!
Regards
Shong