If you want to add number of days from a date and calculate a new date, you can use following code to do so. please note that in this case number of days are variable and calculated runtime.
<set-variable variableName="date" value="#[output application/java var days = vars.inputDays --- (now() - ('P$(days)D' as Period)) as Date {'format' : 'ddMMyyyy'}]" />
Following code can help you to calculate new date after subtracting number of months.
<set-variable variableName="date" value="#[output application/java var days = vars.inputDays --- (now() - ('P$(days)D' as Period)) as Date {'format' : 'ddMMyyyy'}]" />
Following code can help you to calculate new date after subtracting number of years.
<set-variable variableName="date" value="#[output application/java var years = vars.inputYears --- (now() - ('P$(years)Y' as Period)) as Date {'format' : 'ddMMyyyy'}]" />
Following code can decompose date in multiple parts
%dw 2.0
output application/json
var myDate = |2003-10-01T23:57:59.700-03:00|
---
{
year: myDate.year,
month: myDate.month,
day: myDate.day,
hour: myDate.hour,
minutes: myDate.minutes,
seconds: myDate.seconds,
milliseconds: myDate.milliseconds,
nanoseconds: myDate.nanoseconds,
quarter: myDate.quarter,
dayOfWeek: myDate.dayOfWeek,
dayOfYear: myDate.dayOfYear,
offsetSeconds: myDate.offsetSeconds
}
For more information please check
mulesoft documentation