-1

startdate passing in queryparams as string as 07/21/2020 and dayCount as integer 30.

enddate: (vars.asOfDate as Date {format : "mm/dd/yyyy"} + ("P$(numberOfDays)D" as Period)) as Date {format: "MM/dd/yyyy"} as String startdate passing in queryparams as string as 07/21/2020 and dayCount as integer 30.

vars.asOfDate = attributes.queryParams."asOfDate"
vars.dayCount = attributes.queryParams."dayCount"

%dw 2.0
output application/java
var numberOfDays = vars.dayCount
---
{
   enddate: (vars.asOfDate as Date {format : "mm/dd/yyyy"} + ("P$(numberOfDays)D" as Period)) as Date {format: "MM/dd/yyyy"} as String
}

Error:

Message        : "Cannot coerce String (07/21/2020) to Date, caused by: Text '07/21/2020' could not be parsed: Unable to convert `07/21/2020` to Date.
aled
  • 21,330
  • 3
  • 27
  • 34
naren
  • 105
  • 2
  • 13

1 Answers1

0

The problem is that the first string to date conversion uses incorrectly the format "mm" for the month. "m" is the minute format character. You have to use "MM" like in the second conversion.

aled
  • 21,330
  • 3
  • 27
  • 34
  • But it is formatting date as 07/21/2020 instead of that it is showing 2020-08-20 – naren Jul 21 '20 at 14:24
  • How to convert to this format '07/21/2020' ? Even adding String as {format: "MM/dd/yyyy"} showing this '2020-08-20' format only. – naren Jul 21 '20 at 15:17
  • That's strange but it should be a different question. – aled Jul 21 '20 at 17:09