Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
So currently I have a date that I ingested from a filename and it has a format of "dd-MM-yyyy HH:mm" and the HH:mm is currently 00:00. Is it possible that it iterates per 5 minutes 00:00, 00:05 up to 23:55?
This will do it....
public class DateIteration {
private static Date date;
private static int initialDay;
public static Date iterateDates(Date sourceDate, int minutesToAdd) {
if(date==null) {
date = sourceDate;
initialDay = routines.TalendDate.getPartOfDate("DAY_OF_WEEK", sourceDate);
}else{ //New section
if(initialDay!=routines.TalendDate.getPartOfDate("DAY_OF_WEEK", date)){
date = routines.TalendDate.addDate(date,-1,"dd");
}
}
date = routines.TalendDate.addDate(date, 5, "mm");
/* Code moved to the "else" of the first if condition
if(initialDay!=routines.TalendDate.getPartOfDate("DAY_OF_WEEK", date)){
date = routines.TalendDate.addDate(date,-1,"dd");
} */
return date;
}
}
I simply moved the if condition which deals with the amendment of the day in the date to the "else" of the first if condition. What this does is leave the very first time the day ticks over to the next day. Then the next time the method is called it checks the original day against the current value's day. When they do not match, it automatically removes a day.
You will need to ensure that all dates supplied have 00:00:00.000 as the time. If not, you will need to add something to this to ensure that the time is changed to 00:00:00.000.
Thanks again for all your help and apologies for asking so much questions. It works now and yup the dates will have 00:00:00 as the time.