0

I have a query parameter called modifiedDate defined as date-only in the RAML file but when I look in the Mule debugger I see the modifiedDate 2001-10-10 as a string data type.

RAML

...
queryParameters:
   modifiedDate:
   type: date-only
   example: "2001-10-10
...

This is causing me a problem as when I call SQL Server stored procedure it is returning the error "Cannot convert NVARCHAR to Date".

I need to pass the modifiedDate to SQL Server in the format YYYY-MM-DD and as a Date datatype for this to work but I am also have problems converting it to a date datatype in Mule.

How can I change 2001-10-10 into a date datatype and keep the value the same?

I am using Anypoint Studio 6.2.2 and Mule 3.8.3.

Thanks

user3165854
  • 1,505
  • 8
  • 48
  • 100
  • Are you sure you use SQL Server? The error does not seem to be sql server error message, besides, this code `declare @t table (dt date); insert into @t values(N'2001-10-10'), ('2001-10-10')` workse fine in SQL Server – sepupic Jul 21 '17 at 09:46

1 Answers1

1

There are a couple of ways to parse a string as a date in mule

Dataweave:

%dw 1.0
%output application/java
---
{
    "modifiedDate" :  inboundProperties.'http.query.params'['modifiedDate'] as :date
}

will work without having to specify the date format

Groovy

payload['modDate'] = 
    Date.parse("yyyy-MM-dd", message.getInboundProperty('http.query.params')['modifiedDate']);
payload;

Both of these will convert the value into a java.util.Date

Jesse0451
  • 81
  • 8