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

One Star

[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.

Accepted Solutions
Community Manager

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

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
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
Community Manager

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

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
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

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

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
Community Manager

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

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
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

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

Thanks, Shong
Five Stars

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

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.
One Star

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

Created variation of this using a "While" loop.
One Star

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

Thanks everyone for your input. This really helped me !!
One Star

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

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
http://www.talendforge.org/forum/viewtopic.php?id=41029