0

I have an API that takes in a date time as a query string. Date is provided with a Time Zone indicator. When I pass the date with with a "+"in time zone i am getting the default value of a Date Time.

I tried a very simple API that only takes a date from Query String a parameter.

When I pass the date

2019-03-12 07:00:00+05:00

I receive the error :

"The value '2019-03-12 07:00:00 05:00' is not valid."

It looks like the "+"is not interpreted. With a "-" like

2019-03-12 07:00:00-05:00

It works well

It looks like we can't pass a "+" in a query string. How are you suppose to a pass date time with zone indicator in the query string ?

2 Answers 2

2

You have to urlencode the +, since + means "space" in a URL. This should in fact happen for you automatically if you're using a tag helper or something like Html.Action, Url.Action, etc. If you're passing it manually, then it's on you to manually urlencode it.

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

Comments

0

The plus sign in a query string means the space character. %2B is the URL encoded version of + and what you want.

Depending on where you are creating this URL, your can use System.Net.WebUtility.UrlEncode(...) to escape any other characters that need this treatment, as well as the plus sign.

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.