Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Is it possible to use tloop to loop from a start date thru end date?

Hi,
I need to run a trunjob component setting up a context variable to a date - from 1/1/2010 thru 1/31/2010.
Is it possible to use the tloop component ot set the start date and loop by one day until end date is reached?
If not how could I achieve this ?
Thanks in advance.
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi
As I said, you need use TalendDate.diffDate(Date date1, Date date2) to get the time difference first. please see my screenshots.
java.util.Date start_date=TalendDate.parseDate("yyyy-MM-dd", (String)globalMap.get("start_date"));
java.util.Date end_date=TalendDate.parseDate("yyyy-MM-dd", (String)globalMap.get("end_date"));
long l=TalendDate.diffDate(end_date, start_date);
globalMap.put("iterate", l);

Best regards
Shong

View solution in original post

9 Replies
Anonymous
Not applicable
Author

Hello
Set two context variables, start date and end date, use TalendDate.diffDate(Date date1, Date date2) to get the time difference, set this time difference to the 'To' field of tLoop component.
Best regards
Shong
Anonymous
Not applicable
Author

Hi Shong,
IO am still having issues setting this up. I have set up global var - start_date ("2009-01-01" ) and end_date("2009-12-31") but I cannot seem to get the tloop working correctly.
I have included screen shot of what I have.
Can you provide more detail?
Thanks
Anonymous
Not applicable
Author

Hi
As I said, you need use TalendDate.diffDate(Date date1, Date date2) to get the time difference first. please see my screenshots.
java.util.Date start_date=TalendDate.parseDate("yyyy-MM-dd", (String)globalMap.get("start_date"));
java.util.Date end_date=TalendDate.parseDate("yyyy-MM-dd", (String)globalMap.get("end_date"));
long l=TalendDate.diffDate(end_date, start_date);
globalMap.put("iterate", l);

Best regards
Shong
Anonymous
Not applicable
Author

Thanks, Shong
Anonymous
Not applicable
Author

And you can get the date in your next component using
TalendDate.addDate(TalendDate.parseDate("yyyy-MM-dd", (String)globalMap.get("start_date")),+((Integer)globalMap.get("tLoop_1_CURRENT_VALUE")),"dd")

edit: I replace my question with the answer.
Anonymous
Not applicable
Author

Created variation of this using a "While" loop.
Anonymous
Not applicable
Author

Thanks everyone for your input. This really helped me !!
Anonymous
Not applicable
Author

I know this is an old thread. Could anyone help me with screenshots?
I am not able to see any screenshots in this thread.
I want to accomplish something similar. Check below thread
https://community.talend.com/t5/Design-and-Development/resolved-Iterate-over-different-dates-using-d...