Avonelle's Blog

SQL TRY_CONVERT–I need to use this more

By Avonelle Lovhaug on 3/16/2021

I ran into an issue in a SQL stored procedure where I was using ISDATE to test a string before stuffing it into a date column

Except guess what: sometimes ISDATE returns true but it won’t successfully go in a date column. For example, something formatted like this:


Fortunately there is a better solution: use TRY_CONVERT:

SELECT TRY_CONVERT(datetime, 'january,25,1999')

This stackoverflow post got me to the right solution. Phew.