Search code examples
mulemule-studiomulesoftmule-esb

how to format month/day for 2 digits in mule4?


Im trying to create my filename in s3 with month/date format. I dont want May to be printed as 5. It has to be '05' I tried

  now().month as Number {format: "00"}

and

now().month as Number {format: "##"}

Both prints 5. not as 05.

<set-variable value="#[now().year ++ '/' ++ now().month as Number {format: &quot;00&quot;}++ '/'++ now().day as Number {format: &quot;##&quot;} ++'/'++ now() as String {format: &quot;yyyyMMdd_HHmmss&quot;} ++&quot;.json&quot;]"  doc:name="S3-filename" doc:id="ff101e31-4f6c-45f5-9669-a60fbc32204e" variableName="s3filename"/>

Solution

  • Dont's do multiple transformations to date, to number, to string. Transform directly to string. Pay attention that Month is MM (upper case) and minutes are mm (lower case)

    https://simpleflatservice.com/mule4/Date_format.html

    %dw 2.0
    output application/java
    ---
    now() as String {format: "MM"}
    

    enter image description here