Skip to content
Advertisement

SQL Server 2017 Convert Varchar to Date

I have a date stored as nvarchar which I cannot seem to convert to a date.

I have tried the following but get the error message

Conversion failed when converting date and/or time from character string

Any ideas here?

Advertisement

Answer

Find the values that are causing the problem using try_convert():

Once you see what values are causing the problem, you can adjust the conversion logic to convert all values. Or just use try_convert() to get NULL for the non-convertible values.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement