Anonim
Anonim

Reputation: 93

Unix Time formatting in Dataweave

Hi I got some UX time like and I can convert this value in the data time using this:

as DateTime {unit: "milliseconds"} as String {format: 'yyyy-MM-dd hh:mm:ss:SSS'}
{
"test": {
        "1669587277000": 90,
        "1669585177000": 6,
        "1669589077000": 9,
        "1669580977000": 0
    }
}

But how can I convert this key of payload in the dateTime and find the maximum value of the dateTime?

Expected output:

[
{
"2022-11-27 10:14": 90
}
]

Upvotes: 2

Views: 336

Answers (1)

Salim Khan
Salim Khan

Reputation: 4303

You can use the Coercions module to help with this problem or use the standard way of coercing using the way you did.

%dw 2.0
output application/json
import * from dw::util::Coercions
---
[((payload."test" orderBy -$) pluck {
         (toDateTime($$ as Number, "milliseconds")): $
})[0]]

Upvotes: 4

Related Questions