0

Please help me transforming the date-format from

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

to this format

"2022-09-26"

Thanks

3
  • 4
    Does this answer your question? Change a date string format in DataWeave 2 Sep 27, 2022 at 12:48
  • This kind of question has been previously asked and should be closed as a duplicate. Please refer to the link provided or search other answers.
    – aled
    Sep 27, 2022 at 13:01
  • looking to change the "Mon, 26 Sep 2022 14:51:04 +0000" to "2022-09-26" format. However I did not found help in the provided link. %dw 2.0 output application/json var value = "Mon, 26 Sep 2022 14:51:04 +0000" --- date: value as String {format: "yyyy-MM-dd"} tried with above one which is not solving the problem.
    – SP-
    Sep 27, 2022 at 13:25

1 Answer 1

1

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-
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.