1

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

1
  • 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 Commented Jul 21, 2017 at 9:46

1 Answer 1

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

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

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.