Tuesday, December 24, 2024

OIC - Javascript - How to add days to a date (YYYY-MM-DD) format.

Use Case:

This function demonstrates how to add a specific number of days to a date provided in the YYYY-MM-DD format.

Javascript code used:

function addDays(startDate, daysToAdd) {

    // Convert startDate to a Date object

    const rhDate = new Date(startDate.slice(0, 4), startDate.slice(5, 6) - 1, startDate.slice(8));

    rhDate.setDate(rhDate.getDate() + Number(daysToAdd));

    // Format the derived date as YYYY-MM-DD

    const derivedDate = rhDate.getFullYear() + '-' + ('0' + (rhDate.getMonth() + 1)).slice(-2) + '-' + ('0' + rhDate.getDate()).slice(-2);

  return derivedDate;

}

Javascript code snap:


Screeshots:

Flow:


Configure the trigger to take two inputs and one output.





Take the custom defined function and add date and days parameters.

Test:




No comments:

Post a Comment

Featured Post

OIC - Oracle Integration-Bulk load into Oracle ATP OR Oracle ADW

Oracle Integration enhances its database adapters, including Oracle Autonomous Transaction Processing (ATP) and Autonomous Data Warehouse (A...