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.

Keith Fosberg
  • 89
  • 2
  • 9

2 Answers2

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

Chad Gorshing
  • 2,998
  • 32
  • 30
  • 1
    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"} – Keith Fosberg Dec 06 '16 at 12:01
  • 1
    Oh, thanks for the vid also .. bookmarked. I do much better with examples than strict documentation. – Keith Fosberg Dec 06 '16 at 12:09
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"}

satish chennupati
  • 2,602
  • 1
  • 18
  • 27