Loop Start Date through End Date using tLoop
This post I will describe you how to loop through start date to end date. For that we will use tLoop component which will give us two loop options first one is “for loop” and second one is “ while loop”.
Write down below code in tJava.
java.util.Date start_date=TalendDate.parseDate(“yyyy-MM-dd”, “2015-01-01”);
java.util.Date end_date=TalendDate.parseDate(“yyyy-MM-dd”, “2015-01-10”);
long l=TalendDate.diffDate(end_date, start_date);
code look likes as follows.
In above line of you can see we have parse two dates first one is start_date and second one is end_date.
Then we have calculated number of days using TalendDate.diffDate() method it will return number of days in long data type that is stored in variable “l” then this being assigned to “context.days” context variable.
Drop tLoop component next to the tJava and link with “OnsubJobOk” trigger then configure tLoop as follows.
Add tJava component next to tLoop and link with “iterate” flow. tLoop as two global variables which can be used in flow for calculation or manipulation.
Here are those variables.
We will use CURRENT_VALUE to get the day from start day through end date. To print each day on console we will use add date method from TalendDate routine. See the below code, wherein we are adding current value from flow to the start_date to increment start date by one day.
After job run you will see below output on console.