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.
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)
}
Hope it helps.