TRY_PARSE to check valid date



DECLARE @s VARCHAR(6) = '022212'
 

SELECT IIF(TRY_PARSE((Left(@s,2)+'-'+ substring(@s,3,2)+'-20'+right(@s,2)) AS date) IS not NULL, 'True', 'False') AS 'Validdate';


SQL Server 2012 or 2014
Definition:
TRY_PARSE ( string_value AS data_type [ USING culture ] )


 
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s