Generate output with days based on startdate and enddate

Hi Community!

I need to generate a output based on a startdate and enddate field.

Given:

{
  "id": "20738",
  "startdate": "2023-05-01",
  "enddate": "2023-05-10"
}

Output should be like:

{
  "ref_id": "20738",
  "day": "2023-05-01",
  "hours": "8"
},
{
  "ref_id": "20738",
  "day": "2023-05-02",
  "hours": "8"
},
...
{
  "ref_id": "20738",
  "day": "2023-05-10",
  "hours": "8"
}

Is there a easy way to “generate” this kind of output without custom javascript functions?
(I have only core-plan available)

To be more specific. I wrote a AWS Lambda function that works well, but as I understand Make.com only offers something like this in Enterprise Plan, is that right?

function getDates(startDate, stopDate) {
    var dateArray = new Array();
    var currentDate = startDate;
    while (currentDate <= stopDate) {
        if( currentDate.getDay() > 0 && currentDate.getDay() < 6 ) {
            // only push weekdays
            dateArray.push(new Date (currentDate));
        }
        currentDate = new Date(currentDate.setDate(currentDate.getDate()+1));
    }
    return dateArray;
}

exports.handler = async (event, context) => {
    console.log('received:', JSON.stringify(event, null, 2));
    if( !event.start_date || !event.end_date ) {
        throw new Error('This lambda needs start_date as first parameter and end_date as second parameter!');
    }
    
    const startDate = new Date(Date.parse(event.start_date+"T00:00:00"));
    const endDate = new Date(Date.parse(event.end_date+"T00:00:00"));

    console.log('start_date =', startDate.toISOString());
    console.log('end_date =', endDate.toISOString());
    return getDates(startDate, endDate); 
};

Hello :wave:t5:

You could sort it with the combination of the “Repeater”, the “Array aggregator” and a few functions.







The above set of modules uses the first “Set multiple variables” module as an “input” where the date range and ID are set.

The formula in the “Repeater” module changes the dates into the “date” item data type and subtracts the values in order to get the number of days between the two dates. The result such subtraction is in milliseconds, thus it is needed to multiple the number couple of times to get the “days”.
Finally extra “1” is added to the result in order to get the right number of days (=repeats).
The “initial value” is set to 0 as it will be needed in the next step.

The next “Set multiple variables” then uses the “Id” to set the “ref_id”, formats the “day” with the use of “addDays” based on the “increment” set in the previous step. The first date is the same as the “start date” thus we needed 0. Every each repeat then adds extra day.
The “hours” are set dynamically based on the actual date (weekends are counted as 0)

Finally, all results are aggregated into one array.


I extracted the blueprint of this workaround (attached) so you can check how it works and amend it according to your needs.
blueprint (4).json (9.1 KB)

I hope it helps.

Cheerio :cat_roomba: