Reputation: 21
I am using the below data weave for finding the difference in number of days but it is giving output as '4' but it ideally should give result as '23'. Please let me know what must be corrected in the below dataweave.
%dw 2.0
output application/json
import dw::core::Periods
---
Periods::between("19-12-2022" as Date {format: "dd-MM-yyyy"},"15-11-2022" as Date {format: "dd-MM-yyyy"}).days
Upvotes: 0
Views: 77
Reputation: 25699
The problem is that you are looking only at the number of days but the function returns a period. If you remove .days
at the end you will see it is actually returning |P1M4D|
which is a period for 1 month and 4 days.
Instead you probably should use the daysBetween() function:
%dw 2.0
output application/json
---
daysBetween("15-11-2022" as Date {format: "dd-MM-yyyy"}, "19-12-2022" as Date {format: "dd-MM-yyyy"})
That returns 34
by the way which seems about right.
Upvotes: 2