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

Highlighted
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
Highlighted
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

View solution in original post


All Replies
Highlighted
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
Highlighted
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
Highlighted
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

View solution in original post

Highlighted
One Star

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

Thanks, Shong
Highlighted
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.
Highlighted
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.
Highlighted
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 !!
Highlighted
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

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog