0
votes

I am novice in Mule dataweave. I am stuck with a requirement of subtracting 30 days from current date. I spend 2 complete days behind googling around the net, but hopelessly couldn't able to find any useful information on the net. I know one approach of using the Groovy script, but Dataweave being so matured and powerful, can't buy out that there is no option of doing date subtraction.

Thanks in advance for any expert guidance provided to provide resolution! :)

For reference.. - Date noticeDate= currentDate - 30 Days.

2

2 Answers

0
votes

To subtracting 30 days from current date, you can use:

DataWeave code:

%dw 1.0
%output application/json
---
{
    today: now,
    lastMonth: now - |P30D|
}

Or Groovy code:

import groovy.time.TimeCategory;

now = new Date();
println now;

use(TimeCategory) {
    lastMonth = now - 30.days;
    println lastMonth;
}
0
votes

We can try with XQuery 1.0 and XPath 2.0 Functions and Operators for date and time functions. go through the be the below links

https://www.w3.org/TR/xpath-functions/#durations-dates-times

https://docs.mulesoft.com/mule-user-guide/v/3.7/xslt-transformer