简体   繁体   中英

How to perform date operations in Dataweave-Mulesoft

I have a logic to filter out students who joined before 30 days. I have the date of joining and lastdate in an xml element. I have to subtract the dates from these two fields using data weave.

<School>
  <joindate>2015-10-18T00:00:00.000-08:00</joindate>
  <lastdate>2016-01-18</lastdate>
</School>

There are a number of date and time functions available with XPath/XSLT 2.0 and greater. It appears that DataWeave supports up to XSLT 3.0

The following expression will address all of the School elements where the difference in days between lastdate and joindate is less than 30.

//School[days-from-duration(xs:date(lastdate) - xs:date(xs:dateTime(joindate))) lt 30]

Give it a try with the DataWeave Date Time operations:

https://docs.mulesoft.com/mule-user-guide/v/3.7/dataweave-reference-documentation#adding-a-period-of-time

get the values from your XML and store them in variables in DataWeave, cast them as :date and subtract them in the script.

this is an example that gives you an object, i think you are able to fix it from there?

%dw 1.0
%output application/java
%var join = payload.School.joindate as :date
%var last = payload.School.lastdate as :date
---
period: join - last

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM