-2

They asked me to create a SOAP webservice with C#. The problem is they want from me to create a function with datetime parameter, and they want to send a formatted string.

Like below,

Decleration: int func(DateTime)

Then they want to call it like below,

Function Call: int result = func("01/01/2017 01:00:00")

According to my research I didn't find any solution to this.

Is it possible to do declare DateTime and send formatted string to it? Isn't the function decleration must be string, not datetime?

Edit: I was asked this because customer wanted it.

Thanks.

Alexander Chef
  • 378
  • 1
  • 2
  • 13
  • [`DateTime.ToString`](https://msdn.microsoft.com/en-us/library/zdtaw1bw(v=vs.110).aspx) will format a `DateTime` value into a string. Glad you didn't have any trouble creating the rest of the SOAP web service. Mysterious that you want to create a function that returns an integer when it is given a string that contains a date/time. – HABO Apr 08 '17 at 21:31
  • I dont have any trouble on returning values or creating web services. The only problem is in the documentation they wrote to sent the function which i wrote in function call, and for the decleration they want datetime. so i confused. I think it should be declared as string to do that. I didnt get your DateTime.ToString. – Alexander Chef Apr 09 '17 at 08:40

1 Answers1

2

You cannot pass a string type to a method that accepts DateTime .

You can change the method definition to accept a string and then parse the string to get the DateTime value.

Like this :

public int YourFunc(string dateString)
{
   DateTime dt = DateTime.Parse(dateString);
}
Ranjith V
  • 298
  • 1
  • 3
  • 16
  • Yeah. I was also thinking like that. But in the documentation they wrote datetime. So i confused. Thanks. – Alexander Chef Apr 09 '17 at 08:35
  • Sorry for asking again, is there any way to do this in web services? http://stackoverflow.com/questions/300841/how-do-you-globally-set-the-date-format-in-asp-net – Alexander Chef Apr 10 '17 at 12:03