Reputation: 658
How i can format the Date in Dataweave. I tried with the options mentioned in the MuleSoft Documentation. My Date in payload coming as
"noteDate": "2018-12-01 00:00:00",
My Function in Dataweave is
fun getFormattedDate(data) =
if ( data !=null ) data as String {format: "uuuu-MM-dd"}
else
null
But its not formatting at all . Expected output is "2018-12-01"
Upvotes: 0
Views: 590
Reputation: 61
Try with this function which will work for both null and dateTime values.
%dw 2.0
output application/json
fun GenericDate(dateTime) = (dateTime as LocalDateTime {format: "yyyy-MM-dd HH:mm:ss"} as Date) default null
---
GenericDate(payload.noteDate)
Upvotes: 1
Reputation: 4303
Try with this.
%dw 2.0
output application/json
---
payload.noteDate as LocalDateTime {"format": "uuuu-MM-dd HH:mm:ss"} as String {"format": "uuuu-MM-dd"}
Upvotes: 1