VKP
VKP

Reputation: 658

Why Date Field is not formatting in Data weave?

enter image description hereHi i have a Date field which is coming as

{
"noteDate": "2013-12-18T00:00:00"
}

My Dataweave function is

%dw 2.0
output application/json
---
payload.noteDate  as String {"format": "uuuu-MM-dd"}
//formattedDate: |2020-10-01T23:57:59| as String {format: "uuuu-MM-dd"}, // This is in Documentation

The output i am getting is

"2013-12-18T00:00:00"

Expected Output is

"2013-12-18"

How i can do it.

Upvotes: 0

Views: 140

Answers (1)

Michael Jones
Michael Jones

Reputation: 1910

%dw 2.0
output application/json
---
payload.noteDate as Date

That is coming in as a string, not as a date. JSON has no concept of dates.

If you wanted to treat it as a DateTime and then apply a string format you could convert it first (shown below) but just casting it to a Date will do the same.

%dw 2.0
output application/json
---
(payload.noteDate as DateTime) as String { format: "uuuu-MM-dd" }

Upvotes: 3

Related Questions