简体   繁体   中英

Mule ESB Dataweave type cast from string to date format

I have one date field - ddmmyyyy and I want to convert it to date format YYYY-MM-DD T00:00:00 . I have tried with as :date and also with local date then date - as: loacaldate as date

Try this one

%dw 1.0
 %output application/json
 %type mydate = :string { format: "YYYY-MM-DD T00:00:00" }
 ---
{
formatedDate1: |31032016| as :mydate,
}

DataWeave Date which is defined between '|' must follow the ISO-8601 standard . Another thing is, I still unable to put a dynamic value on it, eg: |payload.origDate| .

For this issue, the following script working properly at my machine:

%dw 1.0
%output application/json
---
{
    formattedDate: (payload.origDate as :date {format: "ddMMyyyy"}) as :string {format: "yyyy-MM-dd'T'00:00:00"}
}

Notes: payload.origDate is a String "31032016"

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