score:6

Accepted answer

The managed type that corresponds to the SQL time data type is TimeSpan (or TimeSpan? when nullable), not DateTime – refer to Mapping CLR Parameter Data for the list of type conversions.

You can use TimeSpan.Parse(myString) to convert your string.

Read More

score:-1

Instead of Convert.ToDateTime use DateTime.TryParseExact(yourTimeString, "HH:mm",<other parameters>, out dateTime);

Other parameters are missing. Please look into the DateTime.TryParseExact documentation. But basically it converts your string to dateTime from the format you are specified.

score:0

Use SQL Server's Convert function

convert(DateTime, '20:10:00:000', 114);

See CAST & CONVERT

score:0

You can also use it like this

Convert.ToDateTime(myString).TimeOfDay();

This will return the time . And you can pass this value to Sql command parameter.

TimeOfDay returns TimeSpan object.

TimeSpan tp = Convert.ToDateTime(myString).TimeOfDay();

More questions with similar tag