Search code examples
dataweavemulesoft

Date Conversion YYYYMMDD to YYYY-MM-DD in Data weave 2.0


In an API QueryParameter, I am using the Date as "yyyyMMdd" format. Can anyone help me to convert this to a Date format("yyyy-Mm-dd") in Data weave 2.0

Eg(https://localhost:9103/api/Endpoint?FromDate=20190930)


Solution

  • The answer assumes that you know how to procure the value from a query param. As well I think you meant to format it into "yyyy-MM-dd" format instead of "yyyy-Mm-dd" ?

    if so , the following should help

    Script

    %dw 2.0
    output application/json
    ---
    "20190930"  as Date {"format": "yyyyMMdd"} as String {"format": "yyyy-MM-dd"}
    

    Output

    "2019-09-30"