Skip to main content

Hi,

How to find the difference b/w 2 dates in mule4 in period format ( P1D ).

 

Input:

{

"lsr": "2023-11-03 16:35:45",

"now": "2023-11-05 05:43:49"

}

dwl

%dw 2.3

output application/json

 

var today = now() as DateTime as String {format: "yyyy-MM-dd HH:mm:ss"}

var lsr = "2023-11-03 16:35:45" as LocalDateTime {format: "yyyy-MM-dd HH:mm:ss"}

 

---

{

lsr: lsr,

now: today,

delta: "?"

}

 

Appreciate your help on this.

 

#DataWeave 2​ 

3 answers
  1. Nov 6, 2023, 3:12 PM

    To achieve the desired output format, one possible approach is to utilize the 'between' function.

     

    %dw 2.3

    var today = now() as LocalDateTime {format: "yyyy-MM-dd HH:mm:ss"}

    var lsr = "2023-11-03 16:35:45" as LocalDateTime {format: "yyyy-MM-dd HH:mm:ss"}

    output application/json

    import between from dw::core::Periods

    ---

     

    {

    lsr: lsr,

    now: today,

    delta: between(today,lsr)

    }

    To achieve the desired output format, one possible approach is to utilize the 'between' function. %dw 2. 

    Hope it helps.

0/9000