I want to transform a date which is attribute coming from xml file into csv format using dataweave. now, transformation rule is 'If date is Sunday, make the date minus 6 days'. otherwise keep as it is.
If your input is something like this -
<?xml version='1.0' encoding='UTF-8'?>
<root>
<createDate>2016-05-08</createDate>
</root>
Then you can use below dataweave code to get date as required. When the day is Sunday, subtract 6 days from date -
%dw 1.0
%output application/csv
---
{
row: {
date: (payload.root.createDate as :date) unless
(((payload.root.createDate as :date) as :string {format: "E"}) == 'Sun')
otherwise ((payload.root.createDate as :date) - |P6D|)
}
}
It will output as below -
date
2016-05-02
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.