Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a C# DateTime via the Query String

Tags:

c#

.net

datetime

I have a C# DateTime object. This object includes both the date and time. I need to pass this information to a REST-based service. My question is, how do I format the DateTime, such that I can pass it via the query string, and parse it back into a DateTime on the server-side?

DateTime startDate = GetStartDate(); string url = "http://www.mydomain.com/myservice.svc/[startDateGoesHere]  WebRequest request = HttpWebRequest.Create(url); request.BeginGetResponse(new AsyncCallback(Service_Completed), request); 

Thank you,

like image 790
user208662 Avatar asked May 08 '11 18:05

user208662


People also ask

What is parameter passing in C?

Parameter passing involves passing input parameters into a module (a function in C and a function and procedure in Pascal) and receiving output parameters back from the module. For example a quadratic equation module requires three parameters to be passed to it, these would be a, b and c.

Does C have pass by reference?

There is no pass-by-reference in C.

What is pass by address in C?

If you declare a formal parameter of a function as a pointer type, you are passing that parameter by its address. The pointer is copied, but not the data it points to. So, Pass By Address offers another method of allowing us to change the original argument of a function (like with Pass By Reference).

What is pass result?

Pass by Result:This method uses out-mode semantics. Just before control is transferred back to the caller, the value of the formal parameter is transmitted back to the actual parameter. T his method is sometimes called call by result. In general, pass by result technique is implemented by copy.


1 Answers

Just use ToString() and pass a format e.g.: startDate.ToString("yyyyMMddHHmmss")

And parse it back by using DateTime.ParseExact()

like image 72
Emond Avatar answered Oct 03 '22 11:10

Emond