You can check the expression is a valid date, time or datetime value using ISDATE Function. This function’s return type is int.
Before using this function, be aware that;
- The datetime value range is between 1753-01-01 and 9999-12-31
- The date value range is between 0001-01-01 and 9999-12-31
You can control the expression with IF Clause and ISDATE function as follows. You can find detailed information about SET DATEFORMAT command in the article named “SET DATEFORMAT in SQL Server(TSQL)“
1 2 3 4 5 6 7 8 9 | SET DATEFORMAT ymd IF(ISDATE('2019-02-21')=1) SELECT 'Date is valid.' ELSE SELECT 'Date is not valid'SET DATEFORMAT ydm IF(ISDATE('2019-02-21')=1) SELECT 'Date is valid.' ELSE SELECT 'Date is not valid' |