When I receive a text through the selection option of a web page, I want to convert it to a date and time, but I get this error in the ExceptionDetail.
probably created by IncludeExceptionDetailInFaults = true,
whose value is:
System.FormatException: the string was not recognized as a valid DateTime.
Hei @jalberto
That validation error means you have a datetime type and so you need to convert it to a string.
DateTime.ParseExact( alkfslkjfldksjlkfj ) returns a date, so at the end of that part just add a .ToString DateTime.ParseExact( alkfslkjfldksjlkfj ).ToString(format)
where format is the format string you want to use (if necessary) DateTime.ParseExact( alkfslkjfldksjlkfj ).ToString(“yyyy/MM/dd hh:mm:ss tt”)
Another thing is that the format string inside the ParseExact() needs to be the format that the date is in. Looking at your image it shows the date like “dd/MM/yyyy hh:mm tt”
So, your ParseExact should be like this: DateTime.ParseExact(fechalnicioC.ToString, "dd/MM/yyyy hh:mm tt", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy/MM/dd hh:mm:ss tt")
And like I said, the format in the ParseExact() is the format the initial string is in, and the format in the .ToString() is the format you want to change the date to.