Convert from string to datetime2

时间:2016-08-31 18:47:48

标签: sql sql-server

I am trying to convert a string that is passed from my code to SQL Server stored procedure:

select convert(datetime2, '08/03/20116 12:55:15')

It is throwing an error saying

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.

Do I need to convert the date to specific format like "-" instead of slash in order to get rid of conversion error

Any help will be appreciated.

1 个答案:

答案 0 :(得分:0)

Your example date is in incorrect format. It should be 2016 instead of 20116 as year