0

I've been searching around and can't find (or didn't recognize) a solution to this issue. I'm very new to MEL, so please be kind. :)

I am building a service that will accept 2 dates as strings. I want to be able to accept any (within reason) legitimate string representation of a date and coerce it to a specific format.

So far; everything I try results in errors. To somewhat simplify the process for now, I've started with a string in Dataweave instead of using the actual input for now.

I have this statement: startDate: '2016/11/25 12:00:00' as :localdatetime {format: "yyyy/MM/dd HH:mm:ss"} as :date {format: "yyyymmdd"},

I get this in response: Cannot coerce a :date to a :string, caused by :Unsupported field: MinuteOfHour.

I also tried this: startDate: '2016/11/25 12:00:00' as :date {format: "yyyymmdd"},

I get this response: Cannot coerce a :string to a :date, caused by :Text '2016/11/25 12:00:00' could not be parsed at index 4.

2 Answers 2

3

I would use:

startDate: '2016/11/25 12:00:00' as :localdatetime {format: "yyyy/MM/dd HH:mm:ss"} as :string {format: "yyyymmdd"}

Or:

startDate: '2016/11/25 12:00:00' as :localdatetime {format: "yyyy/MM/dd HH:mm:ss"} as :localdatetime {format: "yyyymm"}

Since you don't have a timezone in your initial data, then I probably wouldn't use date/datetime as they need a timezone.

Shameless plug: I've made a video dealing with dates and DataWeave at https://www.youtube.com/watch?v=tNCqzFEq9IY&t=2s

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks bunches! The issue was 2 fold: matching the pattern and casting it to the correct output class. Here is what I ended up with: agreementDate: "$(flowVars.fullPayload.agreementDate) 12:00:00" as :localdatetime {format: "yyyy-MM-dd HH:mm:ss"} as :string {format: "yyyymmdd"}
Oh, thanks for the vid also .. bookmarked. I do much better with examples than strict documentation.
0

You can use the format "M/d/yyyy" it should work. If you use MM the formatter requires two digit for month

payload.DocDate as :date {format: "M/d/yyyy"}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.