ISDATE

ISDATE is a built-in function in SQL that checks whether an expression is a valid date, time, or datetime value and returns 1 or 0. If the expression is a valid date or time value, ISDATE returns 1. If not, it returns 0.

ISDATE( expression )

  • expression: A valid character string representation of a date or datetime value. This input is checked by the `ISDATE()` function to determine if it can be converted into a valid date or datetime data type in SQL Server.

Example

DECLARE @date AS VARCHAR(30);
SET @date = '2021-08-15';
SELECT ISDATE(@date) AS 'Result';

Output

Result
----------
1

Explanation

In the example provided, ISDATE function is used to check whether a string is a valid date. ‘2021-08-15’ is a valid date, thus output returns 1 (true). If the input is not a valid date, ISDATE function will return 0 (false).

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.