Generating Dates for the Last 30 Days

Support/help with CloverETL implementation problems

KMac21
Posts: 20
Joined: Thu Apr 28, 2016 6:03 pm

Generating Dates for the Last 30 Days

Postby KMac21 » Tue Apr 04, 2017 9:34 pm

I want to generate a list of dates to pass to a URL for a total of 30 days ending with yesterday's date in the format YYYY-MM-DD. I don't know CTL that well so it probably can be done withing a DataGenerator by starting with today - 1 then keep subtracting 1 day until you have a total of 30 days, but I'm not sure of the syntax. Any suggestions would be appreciated!

krizovav
Posts: 7
Joined: Wed Nov 23, 2016 10:17 am

Re: Generating Dates for the Last 30 Days

Postby krizovav » Thu Apr 06, 2017 3:20 pm

Hi,

If you would like to receive a list of dates in one record, it has to be set in metadata at first. Set the Type to “date”, Container type to “list” and Format to “yyyy-MM-dd”, please. Then you can use the code below in DataGenerator.

Code: Select all

function integer generate() {   
   
   date[] list1;
   
   for(integer i = 1; i <= 30; ++i) {
         list1 = push(list1, dateAdd(today(), -i, day));
   }
      
   $out.0.field1 = list1;
   
   return ALL;
}


If you prefer a single record for each date (30 records), put the Normalizer after the DataGenerator and use the code below in it. It will convert multivalue field to multiple records.

Code: Select all

function integer count() {
   
   return length($in.0.field1);
}


function integer transform(integer idx) {

   $out.0.field1 = $in.0.field1[idx];
   return OK;
}


I hope this helps.

Regards,
---
Vladimira Krizova
CloverCARE Support
CloverETL | Rapid Data Integration

Visit us online at http://www.cloveretl.com
How to speed up communication with CloverCARE support

KMac21
Posts: 20
Joined: Thu Apr 28, 2016 6:03 pm

Re: Generating Dates for the Last 30 Days

Postby KMac21 » Thu Apr 06, 2017 7:13 pm

This was exactly what I was looking for. Thank you for your help!