简体   繁体   English

如何在Dataweave-Mulesoft中执行日期操作

[英]How to perform date operations in Dataweave-Mulesoft

I have a logic to filter out students who joined before 30 days. 我有一个逻辑可以过滤掉30天之前加入的学生。 I have the date of joining and lastdate in an xml element. 我在xml元素中有加入日期和lastdate。 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. XPath / XSLT 2.0及更高版本提供了许多日期和时间功能 It appears that DataWeave supports up to XSLT 3.0 看来DataWeave最多支持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. 以下表达式将解决所有日期为lastdatejoindate的天差小于30的School元素。

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

Give it a try with the DataWeave Date Time operations: 尝试使用DataWeave Date Time操作:

https://docs.mulesoft.com/mule-user-guide/v/3.7/dataweave-reference-documentation#adding-a-period-of-time 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. 从XML中获取值并将其存储在DataWeave中的变量中,将其转换为:date并在脚本中减去它们。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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