SP-
SP-

Reputation: 37

Please help the date formating in dataweave2.0

Please help me transforming the date-format from

"Mon, 26 Sep 2022 14:51:04 +0000"

to this format

"2022-09-26"

Thanks

Upvotes: 0

Views: 95

Answers (1)

Emtz
Emtz

Reputation: 26

You must read your input in the incoming format, then you can transform your input to the desired format, here is an example of how you can achieve that,

%dw 2.0
output application/json
var inputDateTime = "Mon, 26 Sep 2022 14:51:04 +0000"
var myDateTime = inputDateTime as DateTime {format: "E, dd MMM yyyy HH:mm:ss Z"}
---
myDateTime as String {format: "yyyy-MM-dd"}

I recommend you go over the documentation pages, for a better understanding of dates formatting in DataWeave 2,

  1. https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-format-dates
  2. https://help.mulesoft.com/s/article/How-to-format-dates-in-DataWeave-2
  3. https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatterBuilder.html#appendPattern-java.lang.String-

Upvotes: 1

Related Questions