SQL Server ISDATE() Function
The SQL Server (Transact-SQL) ISDATE() function returns 1 if the expression is a valid datetime value. Otherwise, it returns 0.
Syntax
ISDATE(expression)
Parameters
expression |
Required. Specify a character string or expression to check whether it is a date. It must be less than 4000 characters. Date and time data types, except datetime and smalldatetime, are not allowed as the argument for this function. |
Return Value
Returns 1 if the expression is a valid datetime value, else returns 0.
Example 1:
The example below shows the usage of ISDATE() function.
SELECT ISDATE('2019-10-25'); Result: 1 SELECT ISDATE('2019-10-25 08:10:25'); Result: 1 SELECT ISDATE('2019-10-25 08:10:25.123'); Result: 1 SELECT ISDATE('08:10:25.123'); Result: 1 SELECT ISDATE('Hello World'); Result: 0 SELECT ISDATE(123); Result: 0 SELECT ISDATE(NULL); Result: 0
Example 2:
Consider a database table called Employee with the following records:
EmpID | Name | City | Age | Date_of_Joining |
---|---|---|---|---|
1 | John | London | 25 | 2018-05-25 |
2 | Marry | New York | 24 | NULL |
3 | Jo | Paris | 27 | 2019-06-09 |
4 | Kim | Amsterdam | 30 | NULL |
5 | Ramesh | New Delhi | 28 | 2019-10-25 |
6 | Suresh | Mumbai | 28 | 2021-12-26 |
The statement given below can be used to check if a record of Date_of_Joining column is a valid date or not.
SELECT *, ISDATE(Date_of_Joining) AS ISDATE_Value FROM Employee;
This will produce the result as shown below:
EmpID | Name | City | Age | Date_of_Joining | ISDATE_Value |
---|---|---|---|---|---|
1 | John | London | 25 | 2018-05-25 | 1 |
2 | Marry | New York | 24 | NULL | 0 |
3 | Jo | Paris | 27 | 2019-06-09 | 1 |
4 | Kim | Amsterdam | 30 | NULL | 0 |
5 | Ramesh | New Delhi | 28 | 2019-10-25 | 1 |
6 | Suresh | Mumbai | 28 | 2021-12-26 | 1 |
❮ SQL Server Functions