T-SQL Tutorial

T-SQL Try_Convert


The Try_Convert function returns a value cast to the specified data type if the cast succeeds; otherwise, returns null.

Try_Convert Syntax


TRY_CONVERT ( data_type [ ( length ) ], expression [, style ] )



Try_Convert Example


SELECT TRY_CONVERT(VARCHAR(15),'08/17/2019',101);

SELECT TRY_CONVERT(date, '08/17/2019') AS Result;
SELECT TRY_CONVERT(date, '08/17/2019 10:05:20') AS Result;

SELECT TRY_CONVERT(datetime, '08/17/2019 10:05:20') AS Result;
SELECT TRY_CONVERT(datetime2, '08/17/2019 10:05:20') AS Result;

See also:
T-SQL Functions
Cast -> Convert -> Parse -> Try_Cast -> Try_Parse