0
votes

I am attempting to convert this datetime string from this format:

'Wed, 09 Aug 2017 20:16:59 +0000'

To this format:

'08092017'

I am using dataweave. Here is my code:

order-date:payload.order.date_created 
as :localdatetime {format: "E, dd M yyyy hh:mm:ss Z"} 
as :string {format: "MMddyyyy"},

I still get the error - Cannot coerce a :string to a :localdatetime, caused by :Text 'Wed, 09 Aug 2017 20:16:59 +0000' could not be parsed at index 8

index 8 appears to the time zone offset, but according to java docs the timezone is specified as uppercase Z

2
Index 8 is where it says Aug. This seems to agree with the solution in the answer. - Ole V.V.

2 Answers

2
votes

If anyone stumbles across this from a google... I had the formatting incorrect. Here is the corrected version:

order-date:payload.order.date_created 
as :localdatetime {format: "E, dd MMM yyyy HH:mm:ss Z"} 
as :string {format: "MMddyyyy"},
0
votes

You should be able to easily do this using dataweave date formatting. Here first you need to convert it to local datetime and then to date format you desire to convert to. Giving some example of date format conversions from Mulesoft documentaions { dates : { date1: normalize("26-JUL-16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"}, date2: normalize("26/JUL/16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"}, date3: normalize("26.JUL.16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"} } }

Please read below links for more understanding of date formatting.

https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-examples#parse-dates-with-different-separators https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-operators#date-time-operations